|
1 | | -# feed-validator |
2 | | -Simple validator for feeds or opensearch.xml based on validator.w3.org/feed |
| 1 | +# Feed validator |
| 2 | +Simple validator for feeds like RSS or Atom. Supports opensearch.xml validation. |
| 3 | +Based on validator.w3.org/feed |
| 4 | + |
| 5 | +Supports plugins for custom checks |
| 6 | + |
| 7 | +## Installation |
| 8 | +``` |
| 9 | +npm install [-g] feed-validator |
| 10 | +``` |
| 11 | + |
| 12 | +## Usage |
| 13 | +``` |
| 14 | +usage: opensearch-validator [-h] [-v] [-c FILE_PATH] [-r REPORTER_NAME] |
| 15 | + [--no-colors] |
| 16 | + url |
| 17 | +
|
| 18 | +Simple validator for RSS, Atom or opensearch.xml that using validator.w3. |
| 19 | +org/feed and plugins |
| 20 | +
|
| 21 | +Positional arguments: |
| 22 | + url Feed url to validate |
| 23 | +
|
| 24 | +Optional arguments: |
| 25 | + -h, --help Show this help message and exit. |
| 26 | + -v, --version Show program's version number and exit. |
| 27 | + -c FILE_PATH, --config FILE_PATH |
| 28 | + Config file path |
| 29 | + -r REPORTER_NAME, --reporter REPORTER_NAME |
| 30 | + Reporter name: text, json |
| 31 | + --no-colors Don't use colors |
| 32 | +``` |
| 33 | + |
| 34 | +## Arguments and options |
| 35 | +Options can be defined by command line and configuration file. |
| 36 | + |
| 37 | +### url |
| 38 | +URL of the validated feed. |
| 39 | + |
| 40 | +### config |
| 41 | +Configuration file. Can be passed from command line. Example of config file see in `examples` folder. |
| 42 | + |
| 43 | +### reporter |
| 44 | +Reporter type: text or JSON. Can be defined in command line: `--reporter json` or in config file: `reporter: 'json'` |
| 45 | + |
| 46 | +### noColors |
| 47 | +Don't use colors in report. Can be passed from command line: `--no-colors` and from config file: `noColors: true`. |
| 48 | + |
| 49 | +### suppress |
| 50 | +You can suppress some messages by defining objects that contains fields to match in config file. |
| 51 | +Example of suppressing: |
| 52 | +```js |
| 53 | +suppress: [ |
| 54 | + {level: 'error', text: 'Unexpected method attribute on Url element'}, |
| 55 | + {level: 'warning', type: 'ShouldIncludeExample'} |
| 56 | +], |
| 57 | +``` |
| 58 | + |
| 59 | +### plugins |
| 60 | +Can be defined in config file (see `examples`). Each plugin is function that take JSON feed representation and returns errors, |
| 61 | +warnings and information messages list. |
| 62 | + |
| 63 | +Plugin function example: |
| 64 | +```js |
| 65 | +/** |
| 66 | + * Check HTTPS in urls from opensearch.xml |
| 67 | + * @param {Object} feedJson Feed JSON representation |
| 68 | + * @param {Object} options Program options |
| 69 | + */ |
| 70 | +function checkHttps(feedJson, options) { |
| 71 | + var path = 'OpenSearchDescription.Url'; |
| 72 | + var urls = _.get(feedJson, path); |
| 73 | + |
| 74 | + var errors = []; |
| 75 | + if (!urls) { |
| 76 | + errors.push({level: 'error', path: path, text: 'No urls'}); |
| 77 | + } |
| 78 | + |
| 79 | + _.each(urls, function (item, i) { |
| 80 | + var url = _.get(item, '$.template'); |
| 81 | + var type = _.get(item, '$.type'); |
| 82 | + |
| 83 | + var errPath = [path, i, '$.template'].join('.'); |
| 84 | + if (!url) { |
| 85 | + errors.push({level: 'error', path: errPath, text: 'No url template for type ' + type}); |
| 86 | + } else if (!/(https:)?\/\//.test(url)) { |
| 87 | + errors.push({level: 'error', path: errPath, text: 'Non HTTPS schema in type ' + type}); |
| 88 | + } |
| 89 | + }); |
| 90 | + return errors; |
| 91 | +} |
| 92 | +``` |
| 93 | +You should define `level` and `text` fields. And you can define your own custom `type` field. |
0 commit comments