Socket
Socket
Sign inDemoInstall

eslint-plugin-json

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-json - npm Package Compare versions

Comparing version 1.4.0 to 2.0.1

LICENSE.txt

29

package.json
{
"name": "eslint-plugin-json",
"version": "1.4.0",
"description": "Lint JSON files",
"version": "2.0.1",
"description": "eslint plugin for JSON files",
"keywords": [

@@ -13,5 +13,9 @@ "eslint",

"author": "Azeem Bande-Ali <a.bandeali@gmail.com>",
"main": "lib/index.js",
"contributors": [
"Adriean Khisbe <adriean.khisbe@live.fr> (https://github.com/AdrieanKhisbe/)"
],
"main": "src/index.js",
"scripts": {
"test": "mocha"
"test": "nyc mocha",
"lint": "eslint src test"
},

@@ -26,14 +30,21 @@ "repository": {

"dependencies": {
"vscode-json-languageservice": "^3.2.1"
"lodash": "^4.17.15",
"vscode-json-languageservice": "^3.3.5"
},
"devDependencies": {
"chai": "^4.2.0",
"eslint": "~5.1.0",
"mocha": "^5.2.0"
"codecov": "^3.6.1",
"eslint": "^6.5.1",
"eslint-config-prettier": "^6.4.0",
"eslint-plugin-prettier": "^3.1.1",
"eslint-plugin-self": "^1.2.0",
"mocha": "^6.2.1",
"nyc": "^14.1.1",
"prettier": "^1.18.2"
},
"engines": {
"node": ">=0.10.0"
"node": ">=8.10.0"
},
"url": "https://github.com/azeemba/eslint-plugin-json",
"license": "ISC"
"license": "MIT"
}
# eslint-plugin-json
[![Build Status](https://travis-ci.org/azeemba/eslint-plugin-json.svg)](https://travis-ci.org/azeemba/eslint-plugin-json) [![Code Climate](https://codeclimate.com/github/azeemba/eslint-plugin-json/badges/gpa.svg)](https://codeclimate.com/github/azeemba/eslint-plugin-json)
[![npm](https://img.shields.io/npm/v/eslint-plugin-json.svg)](https://www.npmjs.com/package/eslint-plugin-json)
[![Build Status](https://travis-ci.org/azeemba/eslint-plugin-json.svg)](https://travis-ci.org/azeemba/eslint-plugin-json)
[![codecov](https://codecov.io/gh/azeemba/eslint-plugin-json/branch/master/graph/badge.svg)](https://codecov.io/gh/azeemba/eslint-plugin-json)
[![dependencies Status](https://david-dm.org/azeemba/eslint-plugin-json/master/status.svg)](https://david-dm.org/adrieankhisbe/eslint-plugin-json/master)
[![Code Climate](https://codeclimate.com/github/azeemba/eslint-plugin-json/badges/gpa.svg)](https://codeclimate.com/github/azeemba/eslint-plugin-json)
Lint JSON files
> Eslint plugin for JSON files
:warning: Starting from **major 2.0**, rules **need to be explicitely activated**.
[See **here** the minimal config to add](#basic-configuration) :rotating_light:
## Installation
You'll first need to install [ESLint](http://eslint.org):
Install `eslint-plugin-json` along [`eslint`](http://eslint.org):
```shell
$ npm install --save-dev eslint eslint-plugin-json
# or
$ yarn add --dev eslint eslint-plugin-json
```
$ npm i eslint --save-dev
**Note:** If you installed ESLint globally (using the `-g` flag) then you must also install `eslint-plugin-json` globally.
## Usage
### Basic configuration
The `json` plugin ship with two recommended config you can use to easily activate it via the `extends` key.
It comes in two flavor: one strict (`recommended`) and one allowing comments `recommended-with-comments`.
```json
{
"extends": ["plugin:json/recommended"]
}
```
Next, install `eslint-plugin-json`:
You can run ESLint on individual JSON files or you can use the `--ext` flag to add JSON files to the list.
```
$ npm install eslint-plugin-json --save-dev
eslint . --ext .json,.js
eslint example.json
```
**Note:** If you installed ESLint globally (using the `-g` flag) then you must also install `eslint-plugin-json` globally.
### Custom Configuration
## Usage
If you want more granular control over which rules, and wich severity you want
Add `json` to the plugins section of your `.eslintrc` configuration file. You can omit the `eslint-plugin-` prefix:
Add `json` to the list of plugins (You can omit the `eslint-plugin-` prefix)
Then pick your rules.
If you want them all, add the `json/json` rule (or its alias `json/*`). (this is what the `recommended` config does)
#### Global rules
The global rules (`json/json` or its alias `json/*`) activate all the rules.
Note it can be configured to ignore errors cause by comments.
To do so, add option `'allowComments'` or `{allowComments: true}`
For instance:
```json

@@ -31,13 +66,33 @@ {

"json"
]
],
"rules": {
"json/*": ["error", "allowComments"],
// or the equivalent:
"json/*": ["error", {"allowComments": true}]
}
}
```
You can run ESLint on individual JSON files or you can use the `--ext` flag to add JSON files to the list.
#### Individual Rules
Here is the list of individual rules (with name in `kebab-case`)in case you want granular error/warning level:
- `json/undefined`
- `json/enum-value-mismatch`
- `json/unexpected-end-of-comment`
- `json/unexpected-end-of-string`
- `json/unexpected-end-of-number`
- `json/invalid-unicode`
- `json/invalid-escape-character`
- `json/invalid-character`
- `json/property-expected`
- `json/comma-expected`
- `json/colon-expected`
- `json/value-expected`
- `json/comma-or-close-backet-expected`
- `json/comma-or-close-brace-expected`
- `json/trailing-comma`
- `json/duplicate-key`
- `json/comment-not-permitted`
- `json/schema-resolve-error`
- `json/unknown` (error that does not match previous ones)
```
eslint . --ext .json --ext .js
eslint example.json
```
## FAQs

@@ -49,6 +104,5 @@

Starting from version 1.3, this plugin relies on what [VSCode](https://github.com/Microsoft/vscode-json-languageservice)
uses for its implementation of JSON validation.
This plugin used to use JSHint, however due to the large size of
this dependency, it was replaced.
uses for its implementation of JSON validation.
Originaly this plugin used to use JSHint, however due to heavy dependencies, it was replaced.

@@ -58,3 +112,3 @@ #### Why doesn't this plugin use `eslint` itself or just `JSON.parse`?

`eslint`'s parser is a JavaScript parser. JSON is a stricter subset and things
that are valid JavaScript are not valid JSON. This is why something more specific
that are valid JavaScript are not valid JSON. This is why something more specific
is more appropriate.

@@ -71,9 +125,6 @@

Now that we have moved to a different implementation for our validation, a lot
more things are possible. Optional support for JSON comments, trailing commas
and schemas are possible.
It is now possible as you can see in the [Configuration section](#configuration)
Additionally, support for autofixing common errors is also possible.
Additionally, support for autofixing common errors could be added in the feature.
#### Is `eslint` really the best tool to lint my JSON?

@@ -85,2 +136,2 @@

Ideally, your editor would natively supports linting JSON. If it doesn't though, then might as well
use this plugin. Hacky linting is better than no linting :)
use this plugin. Hacky linting is better than no linting :)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc