eslint-plugin-yml 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -35,7 +35,7 @@ e.g. [eslint-plugin-yaml](https://www.npmjs.com/package/eslint-plugin-yaml)
35
35
  These plugins use the processor to parse and return the results independently, without providing the ESLint engine with AST and source code text.
36
36
 
37
37
  Plugins don't provide AST, so you can't use directive comments (e.g. `# eslint-disable`).
38
- Plugins don't provide source code text, so you can't use it with plugins and rules that use text (e.g. [eslint-plugin-prettier](https://github.com/prettier/eslint-plugin-prettier), [eol-last](https://eslint.org/docs/rules/eol-last)).
38
+ Plugins don't provide source code text, so you can't use it with plugins and rules that use text (e.g. [eslint-plugin-prettier](https://github.com/prettier/eslint-plugin-prettier), [eol-last](https://eslint.org/docs/rules/eol-last)).
39
39
 
40
40
  **eslint-plugin-yml** works by providing AST and source code text to ESLint.
41
41
 
@@ -74,13 +74,13 @@ module.exports = {
74
74
  extends: [
75
75
  // add more generic rulesets here, such as:
76
76
  // 'eslint:recommended',
77
- 'plugin:yml/standard'
77
+ "plugin:yml/standard",
78
78
  ],
79
79
  rules: {
80
80
  // override/add rules settings here, such as:
81
81
  // 'yml/rule-name': 'error'
82
- }
83
- }
82
+ },
83
+ };
84
84
  ```
85
85
 
86
86
  This plugin provides configs:
@@ -115,6 +115,29 @@ module.exports = {
115
115
  };
116
116
  ```
117
117
 
118
+ #### Parser Options
119
+
120
+ The following parser options for `yaml-eslint-parser` are available by specifying them in [parserOptions](https://eslint.org/docs/latest/user-guide/configuring/language-options#specifying-parser-options) in the ESLint configuration file.
121
+
122
+ ```js
123
+ module.exports = {
124
+ // ...
125
+ overrides: [
126
+ {
127
+ files: ["*.yaml", "*.yml"],
128
+ parser: "yaml-eslint-parser",
129
+ // Options used with yaml-eslint-parser.
130
+ parserOptions: {
131
+ defaultYAMLVersion: "1.2",
132
+ },
133
+ },
134
+ ],
135
+ // ...
136
+ };
137
+ ```
138
+
139
+ See also [https://github.com/ota-meshi/yaml-eslint-parser#readme](https://github.com/ota-meshi/yaml-eslint-parser#readme).
140
+
118
141
  ### Running ESLint from the command line
119
142
 
120
143
  If you want to run `eslint` from the command line, make sure you include the `.yaml` extension using [the `--ext` option](https://eslint.org/docs/user-guide/configuring#specifying-file-extensions-to-lint) or a glob pattern, because ESLint targets only `.js` files by default.
@@ -138,11 +161,7 @@ Example **.vscode/settings.json**:
138
161
 
139
162
  ```json
140
163
  {
141
- "eslint.validate": [
142
- "javascript",
143
- "javascriptreact",
144
- "yaml"
145
- ]
164
+ "eslint.validate": ["javascript", "javascriptreact", "yaml"]
146
165
  }
147
166
  ```
148
167
 
@@ -153,6 +172,7 @@ Following the steps in their help document, you can add YAML files to the scope
153
172
 
154
173
  1. Open the **Settings/Preferences** dialog, go to **Languages and Frameworks** | **JavaScript** | **Code Quality Tools** | **ESLint**, and select **Automatic ESLint configuration** or **Manual ESLint configuration**.
155
174
  2. In the **Run for files** field, update the pattern that defines the set of files to be linted to include YAML files as well:
175
+
156
176
  ```
157
177
  {**/*,*}.{js,ts,jsx,tsx,html,vue,yaml,yml}
158
178
  ^^^^ ^^^
@@ -232,8 +252,8 @@ Please use GitHub's Issues/PRs.
232
252
 
233
253
  ### Development Tools
234
254
 
235
- - `npm test` runs tests and measures coverage.
236
- - `npm run update` runs in order to update readme and recommended configuration.
255
+ - `npm test` runs tests and measures coverage.
256
+ - `npm run update` runs in order to update readme and recommended configuration.
237
257
 
238
258
  ### Working With Rules
239
259
 
@@ -254,7 +274,7 @@ This plugin uses [yaml-eslint-parser](https://github.com/ota-meshi/yaml-eslint-p
254
274
 
255
275
  See the [LICENSE](LICENSE) file for license rights and limitations (MIT).
256
276
 
257
- [YAML]: https://yaml.org/
277
+ [yaml]: https://yaml.org/
258
278
  [eslint-plugin-json-schema-validator]: https://github.com/ota-meshi/eslint-plugin-json-schema-validator
259
279
  [@intlify/eslint-plugin-vue-i18n]: https://github.com/intlify/eslint-plugin-vue-i18n
260
- [Vue I18n]: https://github.com/intlify/vue-i18n-next
280
+ [vue i18n]: https://github.com/intlify/vue-i18n-next
@@ -65,6 +65,7 @@ exports.default = (0, utils_1.createRule)("plain-scalar", {
65
65
  ]
66
66
  : []));
67
67
  const sourceCode = context.getSourceCode();
68
+ let currentDocument;
68
69
  function canToPlain(node) {
69
70
  if (node.value !== node.value.trim()) {
70
71
  return false;
@@ -115,7 +116,9 @@ exports.default = (0, utils_1.createRule)("plain-scalar", {
115
116
  return;
116
117
  }
117
118
  try {
118
- const result = (0, yaml_eslint_parser_1.parseForESLint)(node.value);
119
+ const result = (0, yaml_eslint_parser_1.parseForESLint)(node.value, {
120
+ defaultYAMLVersion: currentDocument === null || currentDocument === void 0 ? void 0 : currentDocument.version,
121
+ });
119
122
  if ((0, yaml_eslint_parser_1.getStaticYAMLValue)(result.ast) !== node.value) {
120
123
  return;
121
124
  }
@@ -147,6 +150,9 @@ exports.default = (0, utils_1.createRule)("plain-scalar", {
147
150
  });
148
151
  }
149
152
  return {
153
+ YAMLDocument(node) {
154
+ currentDocument = node;
155
+ },
150
156
  YAMLScalar(node) {
151
157
  if (!isStringScalar(node)) {
152
158
  return;
package/package.json CHANGED
@@ -1,107 +1,111 @@
1
1
  {
2
- "name": "eslint-plugin-yml",
3
- "version": "1.0.0",
4
- "description": "This ESLint plugin provides linting rules for YAML.",
5
- "main": "lib/index.js",
6
- "files": [
7
- "lib"
8
- ],
9
- "engines": {
10
- "node": "^14.17.0 || >=16.0.0"
11
- },
12
- "scripts": {
13
- "prebuild": "npm run -s clean",
14
- "build": "npm run build:ts",
15
- "build:ts": "tsc --project ./tsconfig.build.json",
16
- "clean": "rimraf .nyc_output dist coverage",
17
- "lint": "eslint . --ext .js,.vue,.ts,.json,.md,.yml,.yaml",
18
- "eslint-fix": "eslint . --ext .js,.vue,.ts,.json,.md,.yml,.yaml --fix",
19
- "pretest:base": "cross-env DEBUG=eslint-plugin-yml*",
20
- "test:base": "mocha --require ts-node/register \"tests/src/**/*.ts\" --reporter dot --timeout 60000",
21
- "test": "npm run test:base",
22
- "cover": "nyc --reporter=lcov npm run test:base",
23
- "test:debug": "mocha --require ts-node/register/transpile-only \"tests/src/**/*.ts\" --reporter dot",
24
- "update": "node --require ts-node/register ./tools/update.ts && npm run eslint-fix && npm run cover",
25
- "new": "ts-node ./tools/new-rule.ts",
26
- "predocs:watch": "npm run build:ts",
27
- "docs:watch": "vuepress dev --debug docs",
28
- "docs:build": "npm run build:ts && vuepress build docs --no-cache",
29
- "preversion": "npm test && git add .",
30
- "version": "env-cmd -e version npm run update && git add .",
31
- "update-fixtures": "ts-node ./tools/update-fixtures.ts && npm run eslint-fix"
32
- },
33
- "repository": {
34
- "type": "git",
35
- "url": "git+https://github.com/ota-meshi/eslint-plugin-yml.git"
36
- },
37
- "keywords": [
38
- "eslint",
39
- "eslintplugin",
40
- "eslint-plugin",
41
- "yaml",
42
- "yml"
43
- ],
44
- "author": "Yosuke Ota",
45
- "funding": "https://github.com/sponsors/ota-meshi",
46
- "license": "MIT",
47
- "bugs": {
48
- "url": "https://github.com/ota-meshi/eslint-plugin-yml/issues"
49
- },
50
- "homepage": "https://ota-meshi.github.io/eslint-plugin-yml/",
51
- "dependencies": {
52
- "debug": "^4.3.2",
53
- "lodash": "^4.17.21",
54
- "natural-compare": "^1.4.0",
55
- "yaml-eslint-parser": "^1.0.0"
56
- },
57
- "peerDependencies": {
58
- "eslint": ">=6.0.0"
59
- },
60
- "devDependencies": {
61
- "@ota-meshi/eslint-plugin": "^0.10.0",
62
- "@types/debug": "^4.1.5",
63
- "@types/eslint": "^8.0.0",
64
- "@types/eslint-scope": "^3.7.0",
65
- "@types/eslint-visitor-keys": "^1.0.0",
66
- "@types/estree": "^0.0.51",
67
- "@types/lodash": "^4.14.158",
68
- "@types/mocha": "^9.0.0",
69
- "@types/natural-compare": "^1.4.0",
70
- "@types/node": "^16.11.3",
71
- "@types/semver": "^7.3.1",
72
- "@typescript-eslint/eslint-plugin": "^5.0.0",
73
- "@typescript-eslint/parser": "^5.0.0",
74
- "cross-env": "^7.0.2",
75
- "env-cmd": "^10.1.0",
76
- "eslint": "^8.0.0",
77
- "eslint-config-prettier": "^8.0.0",
78
- "eslint-plugin-eslint-comments": "^3.2.0",
79
- "eslint-plugin-eslint-plugin": "^4.0.0",
80
- "eslint-plugin-json-schema-validator": "^2.0.0",
81
- "eslint-plugin-jsonc": "^2.0.0",
82
- "eslint-plugin-markdown": "^2.0.0-0",
83
- "eslint-plugin-node": "^11.1.0",
84
- "eslint-plugin-node-dependencies": "^0.8.0",
85
- "eslint-plugin-prettier": "^4.0.0",
86
- "eslint-plugin-regexp": "^1.0.0",
87
- "eslint-plugin-vue": "^9.0.0",
88
- "eslint-plugin-yml": "^0.15.0",
89
- "eslint4b": "^7.3.1",
90
- "espree": "^9.0.0",
91
- "mocha": "^10.0.0",
92
- "monaco-editor": "^0.33.0",
93
- "nyc": "^15.1.0",
94
- "prettier": "^2.2.1",
95
- "raw-loader": "^4.0.1",
96
- "semver": "^7.3.2",
97
- "stylelint": "^14.0.0",
98
- "stylelint-config-recommended-vue": "^1.0.0",
99
- "stylelint-config-standard": "^25.0.0",
100
- "stylelint-plugin-stylus": "^0.13.0",
101
- "ts-node": "^10.0.0",
102
- "typescript": "~4.6.0",
103
- "vue-eslint-editor": "^1.1.0",
104
- "vue-eslint-parser": "^9.0.0",
105
- "vuepress": "^1.5.2"
106
- }
2
+ "name": "eslint-plugin-yml",
3
+ "version": "1.1.0",
4
+ "description": "This ESLint plugin provides linting rules for YAML.",
5
+ "main": "lib/index.js",
6
+ "files": [
7
+ "lib"
8
+ ],
9
+ "engines": {
10
+ "node": "^14.17.0 || >=16.0.0"
11
+ },
12
+ "scripts": {
13
+ "prebuild": "npm run -s clean",
14
+ "build": "npm run build:ts",
15
+ "build:ts": "tsc --project ./tsconfig.build.json",
16
+ "clean": "rimraf .nyc_output dist coverage",
17
+ "lint": "eslint . --ext .js,.vue,.ts,.json,.md,.yml,.yaml",
18
+ "eslint-fix": "eslint . --ext .js,.vue,.ts,.json,.md,.yml,.yaml --fix",
19
+ "pretest:base": "cross-env DEBUG=eslint-plugin-yml*",
20
+ "test:base": "npm run mocha -- \"tests/src/**/*.ts\" --reporter dot --timeout 60000",
21
+ "test": "npm run test:base",
22
+ "cover": "nyc --reporter=lcov npm run test:base",
23
+ "test:debug": "npm run mocha -- \"tests/src/**/*.ts\" --reporter dot",
24
+ "update": "npm run ts -- ./tools/update.ts && npm run eslint-fix && npm run cover",
25
+ "new": "npm run ts -- ./tools/new-rule.ts",
26
+ "predocs:watch": "npm run build:ts",
27
+ "docs:watch": "export NODE_OPTIONS=--openssl-legacy-provider && vuepress dev --debug docs",
28
+ "docs:build": "export NODE_OPTIONS=--openssl-legacy-provider && npm run build:ts && vuepress build docs --no-cache",
29
+ "preversion": "npm test && git add .",
30
+ "version": "env-cmd -e version npm run update && git add .",
31
+ "update-fixtures": "npm run ts -- ./tools/update-fixtures.ts && npm run eslint-fix",
32
+ "ts": "node -r esbuild-register",
33
+ "mocha": "npm run ts -- ./node_modules/mocha/bin/mocha.js"
34
+ },
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "git+https://github.com/ota-meshi/eslint-plugin-yml.git"
38
+ },
39
+ "keywords": [
40
+ "eslint",
41
+ "eslintplugin",
42
+ "eslint-plugin",
43
+ "yaml",
44
+ "yml"
45
+ ],
46
+ "author": "Yosuke Ota",
47
+ "funding": "https://github.com/sponsors/ota-meshi",
48
+ "license": "MIT",
49
+ "bugs": {
50
+ "url": "https://github.com/ota-meshi/eslint-plugin-yml/issues"
51
+ },
52
+ "homepage": "https://ota-meshi.github.io/eslint-plugin-yml/",
53
+ "dependencies": {
54
+ "debug": "^4.3.2",
55
+ "lodash": "^4.17.21",
56
+ "natural-compare": "^1.4.0",
57
+ "yaml-eslint-parser": "^1.1.0"
58
+ },
59
+ "peerDependencies": {
60
+ "eslint": ">=6.0.0"
61
+ },
62
+ "devDependencies": {
63
+ "@ota-meshi/eslint-plugin": "^0.11.0",
64
+ "@types/debug": "^4.1.5",
65
+ "@types/eslint": "^8.0.0",
66
+ "@types/eslint-scope": "^3.7.0",
67
+ "@types/eslint-visitor-keys": "^1.0.0",
68
+ "@types/estree": "^1.0.0",
69
+ "@types/lodash": "^4.14.158",
70
+ "@types/mocha": "^9.0.0",
71
+ "@types/natural-compare": "^1.4.0",
72
+ "@types/node": "^16.11.3",
73
+ "@types/semver": "^7.3.1",
74
+ "@typescript-eslint/eslint-plugin": "^5.0.0",
75
+ "@typescript-eslint/parser": "^5.0.0",
76
+ "cross-env": "^7.0.2",
77
+ "env-cmd": "^10.1.0",
78
+ "esbuild": "^0.14.1",
79
+ "esbuild-register": "^3.2.0",
80
+ "eslint": "^8.0.0",
81
+ "eslint-config-prettier": "^8.0.0",
82
+ "eslint-plugin-eslint-comments": "^3.2.0",
83
+ "eslint-plugin-eslint-plugin": "^5.0.0",
84
+ "eslint-plugin-json-schema-validator": "^4.0.0",
85
+ "eslint-plugin-jsonc": "^2.0.0",
86
+ "eslint-plugin-markdown": "^3.0.0",
87
+ "eslint-plugin-node": "^11.1.0",
88
+ "eslint-plugin-node-dependencies": "^0.9.0",
89
+ "eslint-plugin-prettier": "^4.0.0",
90
+ "eslint-plugin-regexp": "^1.0.0",
91
+ "eslint-plugin-vue": "^9.0.0",
92
+ "eslint-plugin-yml": "^1.0.0",
93
+ "eslint4b": "^7.3.1",
94
+ "espree": "^9.0.0",
95
+ "mocha": "^10.0.0",
96
+ "monaco-editor": "^0.33.0",
97
+ "nyc": "^15.1.0",
98
+ "prettier": "^2.2.1",
99
+ "raw-loader": "^4.0.1",
100
+ "semver": "^7.3.2",
101
+ "stylelint": "^14.9.1",
102
+ "stylelint-config-recommended-vue": "^1.0.0",
103
+ "stylelint-config-standard": "^26.0.0",
104
+ "stylelint-stylus": "^0.16.1",
105
+ "typescript": "~4.7.0",
106
+ "vue-eslint-editor": "^1.1.0",
107
+ "vue-eslint-parser": "^9.0.0",
108
+ "vuepress": "^1.5.2",
109
+ "yaml": "^2.1.1"
110
+ }
107
111
  }