Skip to content

Arondight/eslint-plugin-check-json-value

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

eslint-plugin-check-json-value

ESLint plugin to check value of JSON file.

Installation

You'll first need to install ESLint.

npm install --save-dev eslint

Next, install eslint-plugin-check-json-value.

npm install --save-dev eslint-plugin-check-json-value

Usage

Add check-json-value to the plugins section of your .eslintrc configuration file. You can omit the eslint-plugin- prefix.

{
  "plugins": ["check-json-value"]
}

Then configure the rules you want to use under the rules section.

{
  "rules": {
    "check-json-value/json-lint": [
      "error",
      {
        "lint": true
      }
    ],
    "check-json-value/json-value": [
      "error",
      [
        {
          "file": "member-.+\\.json",
          "path": "gender",
          "values": [
            {
              "type": "string",
              "value": "^(fe)?males$"
            }
          ]
        },
        {
          "file": "data/record-201[0-9]\\.json",
          "path": "records[{{COUNTER1}}].items[{{COUNTER2]}}",
          "values": [
            {
              "type": "number",
              "value": "^\\d{4,6}$"
            }
          ],
          "if": [
            {
              "path": "status",
              "values": [
                {
                  "type": "string",
                  "value": "^need confirm$",
                  "ignoreCase": true
                },
                {
                  "type": "string",
                  "value": "^unconfirmed$",
                  "ignoreCase": true
                }
              ]
            },
            {
              "path": "complete",
              "values": [
                {
                  "type": "boolean",
                  "value": true
                }
              ]
            }
          ],
          "for": [
            {
              "replace": "{{COUNTER1}}",
              "start": 0,
              "end": 10,
              "step": 1
            },
            {
              "replace": "{{COUNTER2}}",
              "start": 0,
              "end": 20,
              "step": 10
            }
          ]
        }
      ]
    ]
  }
}

See schemas of rules check-json-value/json-lint and check-json-value/json-value. Also here are examples of usage in unit tests for rules.

LICENSE

MIT License.