Skip to content

Commit

Permalink
Fix: correct comma-dangle JSON schema (#8864)
Browse files Browse the repository at this point in the history
* Fix: correct comma-dangle JSON schema

* $refs is not part of the spec
* “defs” is inconsistent with the use of “definitions” in other schemas

* Docs: note on usage of $ref in rule schema
  • Loading branch information
Evgeny Poberezkin authored and not-an-aardvark committed Jul 4, 2017
1 parent 676af9e commit 22116f2
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 40 deletions.
2 changes: 2 additions & 0 deletions docs/developer-guide/working-with-rules.md
Expand Up @@ -361,6 +361,8 @@ In the preceding example, the error level is assumed to be the first argument. I

To learn more about JSON Schema, we recommend looking at some [examples](http://json-schema.org/examples.html) to start, and also reading [Understanding JSON Schema](http://spacetelescope.github.io/understanding-json-schema/) (a free ebook).

**Note:** Currently you need to use full JSON Schema object rather than array in case your schema has references ($ref), because in case of array format eslint transforms this array into a single schema without updating references that makes them incorrect (they are ignored).

### Getting the Source

If your rule needs to get the actual JavaScript source to work with, then use the `sourceCode.getText()` method. This method works as follows:
Expand Down
80 changes: 40 additions & 40 deletions lib/rules/comma-dangle.js
Expand Up @@ -81,49 +81,49 @@ module.exports = {
category: "Stylistic Issues",
recommended: false
},

fixable: "code",

schema: [
{
defs: {
value: {
enum: [
"always",
"always-multiline",
"only-multiline",
"never"
]
},
valueWithIgnore: {
anyOf: [
{
$ref: "#/defs/value"
},
{
enum: ["ignore"]
}
]
}
schema: {
definitions: {
value: {
enum: [
"always-multiline",
"always",
"never",
"only-multiline"
]
},
anyOf: [
{
$ref: "#/defs/value"
},
{
type: "object",
properties: {
arrays: { $refs: "#/defs/valueWithIgnore" },
objects: { $refs: "#/defs/valueWithIgnore" },
imports: { $refs: "#/defs/valueWithIgnore" },
exports: { $refs: "#/defs/valueWithIgnore" },
functions: { $refs: "#/defs/valueWithIgnore" }
valueWithIgnore: {
enum: [
"always-multiline",
"always",
"ignore",
"never",
"only-multiline"
]
}
},
type: "array",
items: [
{
oneOf: [
{
$ref: "#/definitions/value"
},
additionalProperties: false
}
]
}
]
{
type: "object",
properties: {
arrays: { $ref: "#/definitions/valueWithIgnore" },
objects: { $ref: "#/definitions/valueWithIgnore" },
imports: { $ref: "#/definitions/valueWithIgnore" },
exports: { $ref: "#/definitions/valueWithIgnore" },
functions: { $ref: "#/definitions/valueWithIgnore" }
},
additionalProperties: false
}
]
}
]
}
},

create(context) {
Expand Down

0 comments on commit 22116f2

Please sign in to comment.