From 39115c8b71d2629161359f6456f47fdbd552fddd Mon Sep 17 00:00:00 2001 From: gfyoung Date: Thu, 15 Jul 2021 01:56:07 -0700 Subject: [PATCH 01/12] Docs: provide more context to no-eq-null (#14801) * Docs: provide more context to no-eq-null * Encourage use of the more powerful eqeqeq rule for linting equality checks. * Indicate this rule is compatible with an analogous rule in JSHint. xref https://github.com/eslint/eslint/pull/179 closes https://github.com/eslint/eslint/issues/14749 * Update docs/rules/no-eq-null.md Co-authored-by: Brandon Mills Co-authored-by: Brandon Mills --- docs/rules/no-eq-null.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/rules/no-eq-null.md b/docs/rules/no-eq-null.md index df8f97a5eba..7b0f5df142a 100644 --- a/docs/rules/no-eq-null.md +++ b/docs/rules/no-eq-null.md @@ -39,3 +39,11 @@ while (qux !== null) { baz(); } ``` + +## Compatibility + +* **JSHint**: This rule corresponds to `eqnull` rule of JSHint. + +## When Not To Use It + +If you want to enforce type-checking operations in general, use the more powerful [eqeqeq](./eqeqeq) instead. From e0e8e308929c9c66612505f2da89043f8592eea7 Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Sat, 17 Jul 2021 05:55:23 +0530 Subject: [PATCH 02/12] Docs: update BUG_REPORT template (#14787) --- .github/ISSUE_TEMPLATE/BUG_REPORT.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/BUG_REPORT.md b/.github/ISSUE_TEMPLATE/BUG_REPORT.md index 9b46d2944f2..b368e5009c4 100644 --- a/.github/ISSUE_TEMPLATE/BUG_REPORT.md +++ b/.github/ISSUE_TEMPLATE/BUG_REPORT.md @@ -72,7 +72,7 @@ assignees: '' 1. -1. -1. +2. +3. **Are you willing to submit a pull request to fix this bug?** From a96b05f6c5649cfee112d605c91d95aa191e2f78 Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Sun, 18 Jul 2021 03:04:43 +0530 Subject: [PATCH 03/12] Update: add end location to report in `consistent-return` (refs #12334) (#14798) * Update: add end location to report in `consistent-return` * Update: report end location for `function` keyword --- lib/rules/consistent-return.js | 6 +- tests/lib/rules/consistent-return.js | 112 ++++++++++++++++++++++----- 2 files changed, 94 insertions(+), 24 deletions(-) diff --git a/lib/rules/consistent-return.js b/lib/rules/consistent-return.js index a250430cb76..0e20209af56 100644 --- a/lib/rules/consistent-return.js +++ b/lib/rules/consistent-return.js @@ -104,18 +104,18 @@ module.exports = { } else if (node.type === "ArrowFunctionExpression") { // `=>` token - loc = context.getSourceCode().getTokenBefore(node.body, astUtils.isArrowToken).loc.start; + loc = context.getSourceCode().getTokenBefore(node.body, astUtils.isArrowToken).loc; } else if ( node.parent.type === "MethodDefinition" || (node.parent.type === "Property" && node.parent.method) ) { // Method name. - loc = node.parent.key.loc.start; + loc = node.parent.key.loc; } else { // Function name or `function` keyword. - loc = (node.id || node).loc.start; + loc = (node.id || context.getSourceCode().getFirstToken(node)).loc; } if (!name) { diff --git a/tests/lib/rules/consistent-return.js b/tests/lib/rules/consistent-return.js index 53781ea423d..16a1ed97a19 100644 --- a/tests/lib/rules/consistent-return.js +++ b/tests/lib/rules/consistent-return.js @@ -52,7 +52,11 @@ ruleTester.run("consistent-return", rule, { { messageId: "missingReturnValue", data: { name: "Function 'foo'" }, - type: "ReturnStatement" + type: "ReturnStatement", + line: 1, + column: 46, + endLine: 1, + endColumn: 53 } ] }, @@ -63,7 +67,11 @@ ruleTester.run("consistent-return", rule, { { messageId: "missingReturnValue", data: { name: "Arrow function" }, - type: "ReturnStatement" + type: "ReturnStatement", + line: 1, + column: 47, + endLine: 1, + endColumn: 54 } ] }, @@ -73,7 +81,11 @@ ruleTester.run("consistent-return", rule, { { messageId: "unexpectedReturnValue", data: { name: "Function 'foo'" }, - type: "ReturnStatement" + type: "ReturnStatement", + line: 1, + column: 41, + endLine: 1, + endColumn: 54 } ] }, @@ -83,7 +95,11 @@ ruleTester.run("consistent-return", rule, { { messageId: "missingReturnValue", data: { name: "Function" }, - type: "ReturnStatement" + type: "ReturnStatement", + line: 1, + column: 44, + endLine: 1, + endColumn: 51 } ] }, @@ -93,7 +109,11 @@ ruleTester.run("consistent-return", rule, { { messageId: "unexpectedReturnValue", data: { name: "Function" }, - type: "ReturnStatement" + type: "ReturnStatement", + line: 1, + column: 39, + endLine: 1, + endColumn: 52 } ] }, @@ -104,7 +124,11 @@ ruleTester.run("consistent-return", rule, { { messageId: "unexpectedReturnValue", data: { name: "Arrow function" }, - type: "ReturnStatement" + type: "ReturnStatement", + line: 1, + column: 33, + endLine: 1, + endColumn: 46 } ] }, @@ -116,7 +140,10 @@ ruleTester.run("consistent-return", rule, { messageId: "missingReturnValue", data: { name: "Function 'foo'" }, type: "ReturnStatement", - column: 41 + line: 1, + column: 41, + endLine: 1, + endColumn: 58 } ] }, @@ -128,7 +155,10 @@ ruleTester.run("consistent-return", rule, { messageId: "missingReturnValue", data: { name: "Function 'foo'" }, type: "ReturnStatement", - column: 41 + line: 1, + column: 41, + endLine: 1, + endColumn: 55 } ] }, @@ -140,7 +170,10 @@ ruleTester.run("consistent-return", rule, { messageId: "unexpectedReturnValue", data: { name: "Function 'foo'" }, type: "ReturnStatement", - column: 46 + line: 1, + column: 46, + endLine: 1, + endColumn: 58 } ] }, @@ -152,7 +185,10 @@ ruleTester.run("consistent-return", rule, { messageId: "unexpectedReturnValue", data: { name: "Function 'foo'" }, type: "ReturnStatement", - column: 43 + line: 1, + column: 43, + endLine: 1, + endColumn: 55 } ] }, @@ -163,7 +199,11 @@ ruleTester.run("consistent-return", rule, { { messageId: "missingReturnValue", data: { name: "Program" }, - type: "ReturnStatement" + type: "ReturnStatement", + line: 1, + column: 25, + endLine: 1, + endColumn: 32 } ] }, @@ -174,7 +214,10 @@ ruleTester.run("consistent-return", rule, { messageId: "missingReturn", data: { name: "function 'foo'" }, type: "FunctionDeclaration", - column: 10 + line: 1, + column: 10, + endLine: 1, + endColumn: 13 } ] }, @@ -185,7 +228,10 @@ ruleTester.run("consistent-return", rule, { messageId: "missingReturn", data: { name: "function '_foo'" }, type: "FunctionDeclaration", - column: 10 + line: 1, + column: 10, + endLine: 1, + endColumn: 14 } ] }, @@ -196,7 +242,10 @@ ruleTester.run("consistent-return", rule, { messageId: "missingReturn", data: { name: "function 'foo'" }, type: "FunctionExpression", - column: 12 + line: 1, + column: 12, + endLine: 1, + endColumn: 15 } ] }, @@ -207,7 +256,10 @@ ruleTester.run("consistent-return", rule, { messageId: "missingReturn", data: { name: "function" }, type: "FunctionExpression", - column: 3 + line: 1, + column: 3, + endLine: 1, + endColumn: 11 } ] }, @@ -219,7 +271,10 @@ ruleTester.run("consistent-return", rule, { messageId: "missingReturn", data: { name: "arrow function" }, type: "ArrowFunctionExpression", - column: 6 + line: 1, + column: 6, + endLine: 1, + endColumn: 8 } ] }, @@ -231,7 +286,10 @@ ruleTester.run("consistent-return", rule, { messageId: "missingReturn", data: { name: "method 'foo'" }, type: "FunctionExpression", - column: 12 + line: 1, + column: 12, + endLine: 1, + endColumn: 15 } ] }, @@ -243,7 +301,10 @@ ruleTester.run("consistent-return", rule, { messageId: "missingReturn", data: { name: "method 'foo'" }, type: "FunctionExpression", - column: 10 + line: 1, + column: 10, + endLine: 1, + endColumn: 13 } ] }, @@ -255,7 +316,10 @@ ruleTester.run("consistent-return", rule, { messageId: "missingReturn", data: { name: "program" }, type: "Program", - column: 1 + line: 1, + column: 1, + endLine: void 0, + endColumn: void 0 } ] }, @@ -267,7 +331,10 @@ ruleTester.run("consistent-return", rule, { messageId: "missingReturn", data: { name: "method 'CapitalizedFunction'" }, type: "FunctionExpression", - column: 11 + line: 1, + column: 11, + endLine: 1, + endColumn: 30 } ] }, @@ -279,7 +346,10 @@ ruleTester.run("consistent-return", rule, { messageId: "missingReturn", data: { name: "method 'constructor'" }, type: "FunctionExpression", - column: 4 + line: 1, + column: 4, + endLine: 1, + endColumn: 15 } ] } From efdbb1227019427ec2d968a8d6e9151dd8a77c35 Mon Sep 17 00:00:00 2001 From: Brandon Mills Date: Sat, 17 Jul 2021 17:43:44 -0400 Subject: [PATCH 04/12] Upgrade: @eslint/eslintrc to v0.4.3 (#14808) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8fabe0a68f5..0f7db14d071 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "bugs": "https://github.com/eslint/eslint/issues/", "dependencies": { "@babel/code-frame": "7.12.11", - "@eslint/eslintrc": "^0.4.2", + "@eslint/eslintrc": "^0.4.3", "@humanwhocodes/config-array": "^0.5.0", "ajv": "^6.10.0", "chalk": "^4.0.0", From faf2fe8745b02cb53d1db3899840a032b70ded21 Mon Sep 17 00:00:00 2001 From: ESLint Jenkins Date: Sat, 17 Jul 2021 17:56:19 -0400 Subject: [PATCH 05/12] Build: changelog update for 7.31.0 --- CHANGELOG.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f4a316be0f9..bd7fb6b5e9a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,16 @@ +v7.31.0 - July 17, 2021 + +* [`efdbb12`](https://github.com/eslint/eslint/commit/efdbb1227019427ec2d968a8d6e9151dd8a77c35) Upgrade: @eslint/eslintrc to v0.4.3 (#14808) (Brandon Mills) +* [`a96b05f`](https://github.com/eslint/eslint/commit/a96b05f6c5649cfee112d605c91d95aa191e2f78) Update: add end location to report in `consistent-return` (refs #12334) (#14798) (Nitin Kumar) +* [`e0e8e30`](https://github.com/eslint/eslint/commit/e0e8e308929c9c66612505f2da89043f8592eea7) Docs: update BUG_REPORT template (#14787) (Nitin Kumar) +* [`39115c8`](https://github.com/eslint/eslint/commit/39115c8b71d2629161359f6456f47fdbd552fddd) Docs: provide more context to no-eq-null (#14801) (gfyoung) +* [`9a3c73c`](https://github.com/eslint/eslint/commit/9a3c73c130d437a65f4edba0dcb63390e68cac41) Docs: fix a broken link (#14790) (Sam Chen) +* [`ddffa8a`](https://github.com/eslint/eslint/commit/ddffa8ad58b4b124b08061e9045fdb5370cbdbe3) Update: Indicating the operator in question (#14764) (Paul Smith) +* [`bba714c`](https://github.com/eslint/eslint/commit/bba714c2ed813821ed288fbc07722cdde6e534fe) Update: Clarifying what changes need to be made in no-mixed-operators (#14765) (Paul Smith) +* [`b0d22e3`](https://github.com/eslint/eslint/commit/b0d22e3eff18ea7f08189134c07cddceaec69a09) Docs: Mention benefit of providing `meta.docs.url` (#14774) (Bryan Mishkin) +* [`000cc79`](https://github.com/eslint/eslint/commit/000cc796fd487e7b9ba8bcc5857dd691044479cc) Sponsors: Sync README with website (ESLint Jenkins) +* [`a6a7438`](https://github.com/eslint/eslint/commit/a6a7438502abc6a1e29ec35cfbe2058ffc0803b1) Chore: pin fs-teardown@0.1.1 (#14771) (Milos Djermanovic) + v7.30.0 - July 2, 2021 * [`5f74642`](https://github.com/eslint/eslint/commit/5f746420700d457b92dd86659de588d272937b79) Chore: don't check Program.start in SourceCode#getComments (refs #14744) (#14748) (Milos Djermanovic) From ad3951889f0e724379751ed0a968d547a2e67e39 Mon Sep 17 00:00:00 2001 From: ESLint Jenkins Date: Sat, 17 Jul 2021 17:56:19 -0400 Subject: [PATCH 06/12] 7.31.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0f7db14d071..0e64b624b96 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "eslint", - "version": "7.30.0", + "version": "7.31.0", "author": "Nicholas C. Zakas ", "description": "An AST-based pattern checker for JavaScript.", "bin": { From 6641d88e17d952a8e51df5e0d3882a842d4c3f35 Mon Sep 17 00:00:00 2001 From: ESLint Jenkins Date: Sat, 17 Jul 2021 18:01:34 -0400 Subject: [PATCH 07/12] Docs: Update README team and sponsors --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 68982812e3b..804310d8c1f 100644 --- a/README.md +++ b/README.md @@ -254,6 +254,16 @@ Toru Nagashima The people who review and fix bugs and help triage issues.
+ +
+Brett Zamir +
+
+ +
+Bryan Mishkin +
+

Pig Fang From 60df44c79b0f74406119c0c040a360ca84e721fc Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Thu, 22 Jul 2021 06:20:18 +0530 Subject: [PATCH 08/12] Chore: use `actions/setup-node@v2` (#14816) * Chore: use `actions/setup-node@v2` * Chore: use actions/setup-node@v2 77937d8 --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6ba0bdc384b..b1972878e94 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - uses: actions/setup-node@v1 + - uses: actions/setup-node@v2 - name: Install Packages run: npm install - name: Lint Files @@ -35,7 +35,7 @@ jobs: runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v2 - - uses: actions/setup-node@v1 + - uses: actions/setup-node@v2 with: node-version: ${{ matrix.node }} - name: Install Packages @@ -50,7 +50,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - uses: actions/setup-node@v1 + - uses: actions/setup-node@v2 with: node-version: '12' - name: Install Packages From ed945bd662714b1917e9de71d5b322a28be9161b Mon Sep 17 00:00:00 2001 From: Sam Chen Date: Mon, 26 Jul 2021 04:26:21 +0800 Subject: [PATCH 09/12] Docs: fix multiple broken links (#14833) --- docs/rules/space-after-keywords.md | 2 +- docs/rules/space-before-keywords.md | 2 +- docs/rules/space-return-throw-case.md | 2 +- docs/user-guide/configuring/configuration-files.md | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/rules/space-after-keywords.md b/docs/rules/space-after-keywords.md index af1b739fe0e..7f6182b227a 100644 --- a/docs/rules/space-after-keywords.md +++ b/docs/rules/space-after-keywords.md @@ -2,7 +2,7 @@ (removed) This rule was **removed** in ESLint v2.0 and replaced by the [keyword-spacing](keyword-spacing.md) rule. -(fixable) The `--fix` option on the [command line](../user-guide/command-line-interface#fix) automatically fixed problems reported by this rule. +(fixable) The `--fix` option on the [command line](../user-guide/command-line-interface#--fix) automatically fixed problems reported by this rule. Some style guides will require or disallow spaces following the certain keywords. diff --git a/docs/rules/space-before-keywords.md b/docs/rules/space-before-keywords.md index 8adf593a6c7..077c9a322fa 100644 --- a/docs/rules/space-before-keywords.md +++ b/docs/rules/space-before-keywords.md @@ -2,7 +2,7 @@ (removed) This rule was **removed** in ESLint v2.0 and **replaced** by the [keyword-spacing](keyword-spacing.md) rule. -(fixable) The `--fix` option on the [command line](../user-guide/command-line-interface#fix) automatically fixed problems reported by this rule. +(fixable) The `--fix` option on the [command line](../user-guide/command-line-interface#--fix) automatically fixed problems reported by this rule. Keywords are syntax elements of JavaScript, such as `function` and `if`. These identifiers have special meaning to the language and so often appear in a different color in code editors. As an important part of the language, style guides often refer to the spacing that should be used around keywords. For example, you might have a style guide that says keywords should be always be preceded by spaces, which would mean `if-else` statements must look like this: diff --git a/docs/rules/space-return-throw-case.md b/docs/rules/space-return-throw-case.md index 024eb3c9586..ff55f7f5eff 100644 --- a/docs/rules/space-return-throw-case.md +++ b/docs/rules/space-return-throw-case.md @@ -2,7 +2,7 @@ (removed) This rule was **removed** in ESLint v2.0 and **replaced** by the [keyword-spacing](keyword-spacing.md) rule. -(fixable) The `--fix` option on the [command line](../user-guide/command-line-interface#fix) automatically fixed problems reported by this rule. +(fixable) The `--fix` option on the [command line](../user-guide/command-line-interface#--fix) automatically fixed problems reported by this rule. Require spaces following `return`, `throw`, and `case`. diff --git a/docs/user-guide/configuring/configuration-files.md b/docs/user-guide/configuring/configuration-files.md index bf9b70d12db..244fb0e9855 100644 --- a/docs/user-guide/configuring/configuration-files.md +++ b/docs/user-guide/configuring/configuration-files.md @@ -297,7 +297,7 @@ The `extends` property value can be `"eslint:all"` to enable all core rules in t You might enable all core rules as a shortcut to explore rules and options while you decide on the configuration for a project, especially if you rarely override options or disable rules. The default options for rules are not endorsements by ESLint (for example, the default option for the [`quotes`](https://eslint.org/docs/rules/quotes) rule does not mean double quotes are better than single quotes). -If your configuration extends `eslint:all`, after you upgrade to a newer major or minor version of ESLint, review the reported problems before you use the `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fix), so you know if a new fixable rule will make changes to the code. +If your configuration extends `eslint:all`, after you upgrade to a newer major or minor version of ESLint, review the reported problems before you use the `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#--fix), so you know if a new fixable rule will make changes to the code. Example of a configuration file in JavaScript format: From eba0c4595c126a91f700d5f2e8723ec3f820a830 Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Mon, 26 Jul 2021 02:10:08 +0530 Subject: [PATCH 10/12] Chore: assertions on reporting loc in `unicode-bom` (refs #12334) (#14809) * Update: add end location to report in `unicode-bom` * Update: report start location only --- tests/lib/rules/unicode-bom.js | 36 ++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/tests/lib/rules/unicode-bom.js b/tests/lib/rules/unicode-bom.js index 0b94a690291..62abee69870 100644 --- a/tests/lib/rules/unicode-bom.js +++ b/tests/lib/rules/unicode-bom.js @@ -41,24 +41,52 @@ ruleTester.run("unicode-bom", rule, { code: "var a = 123;", output: "\uFEFFvar a = 123;", options: ["always"], - errors: [expectedError] + errors: [{ + ...expectedError, + line: 1, + column: 1, + endLine: void 0, + endColumn: void 0 + + }] }, { code: " // here's a comment \nvar a = 123;", output: "\uFEFF // here's a comment \nvar a = 123;", options: ["always"], - errors: [expectedError] + errors: [{ + ...expectedError, + line: 1, + column: 1, + endLine: void 0, + endColumn: void 0 + + }] }, { code: "\uFEFF var a = 123;", output: " var a = 123;", - errors: [unexpectedError] + errors: [{ + ...unexpectedError, + line: 1, + column: 1, + endLine: void 0, + endColumn: void 0 + + }] }, { code: "\uFEFF var a = 123;", output: " var a = 123;", options: ["never"], - errors: [unexpectedError] + errors: [{ + ...unexpectedError, + line: 1, + column: 1, + endLine: void 0, + endColumn: void 0 + + }] } ] }); From f9c164f7b74ca73384c8c80eed5bdbe359b44f6c Mon Sep 17 00:00:00 2001 From: "Nicholas C. Zakas" Date: Mon, 26 Jul 2021 17:32:52 -0700 Subject: [PATCH 11/12] Docs: New syntax issue template (#14826) --- .github/ISSUE_TEMPLATE/NEW_SYNTAX.md | 43 ++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/NEW_SYNTAX.md diff --git a/.github/ISSUE_TEMPLATE/NEW_SYNTAX.md b/.github/ISSUE_TEMPLATE/NEW_SYNTAX.md new file mode 100644 index 00000000000..e03cb6e11bd --- /dev/null +++ b/.github/ISSUE_TEMPLATE/NEW_SYNTAX.md @@ -0,0 +1,43 @@ +--- +name: "\U0001F4DD Request new syntax support" +about: Request new stage 4 syntax be supported. +title: '' +labels: + - core + - new syntax +assignees: '' + +--- + + + +**What is the name of the syntax to implement?** + + + +**Please provide the TC39 URL for the syntax proposal:** + + + +**Please provide some example code for the new syntax:** + +```js +// example code here +``` + +## Implementation Checklist + +Please check off all items that have already been completed. Be sure to paste the pull request URLs next to each item so we can verify the work as done. + +- [ ] Ecma262 update: +- [ ] ESTree update: +- [ ] Acorn update: +- [ ] `eslint-visitor-keys` update: +- [ ] `espree` update: +- [ ] `eslint-scope` update: +- [ ] `eslint` update: + +**Are you willing to submit a pull request to implement this syntax?** From 8be8a36010145dfcd31cbdd4f781a91989e3b1bd Mon Sep 17 00:00:00 2001 From: Bryan Mishkin <698306+bmish@users.noreply.github.com> Date: Mon, 26 Jul 2021 19:56:48 -0700 Subject: [PATCH 12/12] Chore: Adopt `eslint-plugin/require-meta-docs-url` rule internally (#14823) https://github.com/not-an-aardvark/eslint-plugin-eslint-plugin/blob/master/docs/rules/require-meta-docs-url.md --- .eslintrc.js | 2 +- package.json | 2 +- .../internal-rules/consistent-docs-url.js | 105 ---------------- tools/internal-rules/consistent-docs-url.js | 119 ------------------ 4 files changed, 2 insertions(+), 226 deletions(-) delete mode 100644 tests/tools/internal-rules/consistent-docs-url.js delete mode 100644 tools/internal-rules/consistent-docs-url.js diff --git a/.eslintrc.js b/.eslintrc.js index 668bc2747c5..a7e0f1153d8 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -88,7 +88,7 @@ module.exports = { files: ["lib/rules/*"], excludedFiles: ["index.js"], rules: { - "internal-rules/consistent-docs-url": "error" + "eslint-plugin/require-meta-docs-url": ["error", { pattern: "https://eslint.org/docs/rules/{{name}}" }] } }, { diff --git a/package.json b/package.json index 0e64b624b96..ea08a90ef65 100644 --- a/package.json +++ b/package.json @@ -96,7 +96,7 @@ "ejs": "^3.0.2", "eslint": "file:.", "eslint-config-eslint": "file:packages/eslint-config-eslint", - "eslint-plugin-eslint-plugin": "^3.2.0", + "eslint-plugin-eslint-plugin": "^3.4.0", "eslint-plugin-internal-rules": "file:tools/internal-rules", "eslint-plugin-jsdoc": "^25.4.3", "eslint-plugin-node": "^11.1.0", diff --git a/tests/tools/internal-rules/consistent-docs-url.js b/tests/tools/internal-rules/consistent-docs-url.js deleted file mode 100644 index 4b3d3a05b67..00000000000 --- a/tests/tools/internal-rules/consistent-docs-url.js +++ /dev/null @@ -1,105 +0,0 @@ -/** - * @fileoverview Tests for internal-consistent-docs-url rule. - * @author Patrick McElhaney - */ - -"use strict"; - -//------------------------------------------------------------------------------ -// Requirements -//------------------------------------------------------------------------------ - -const rule = require("../../../tools/internal-rules/consistent-docs-url"), - { RuleTester } = require("../../../lib/rule-tester"); - -//------------------------------------------------------------------------------ -// Tests -//------------------------------------------------------------------------------ - -const ruleTester = new RuleTester(); - -ruleTester.run("consistent-docs-url", rule, { - valid: [ - - // wrong exports format: "internal-no-invalid-meta" reports this already - [ - "module.exports = function(context) {", - " return {", - " Program: function(node) {}", - " };", - "};" - ].join("\n"), - [ - "module.exports = {", - " meta: {", - " docs: {", - " url: 'https://eslint.org/docs/rules/'", - " }", - " },", - " create: function(context) {", - " return {};", - " }", - "};" - ].join("\n") - ], - invalid: [ - { - code: [ - "module.exports = {", - " meta: {", - " },", - - " create: function(context) {", - " return {};", - " }", - "};" - ].join("\n"), - errors: [{ - messageId: "missingMetaDocs", - line: 2, - column: 5 - }] - }, - { - code: [ - "module.exports = {", - " meta: {", - " docs: {}", - " },", - - " create: function(context) {", - " return {};", - " }", - "};" - ].join("\n"), - errors: [{ - messageId: "missingMetaDocsUrl", - line: 3, - column: 9 - }] - }, - { - code: [ - "module.exports = {", - " meta: {", - " docs: {", - " url: 'http://example.com/wrong-url'", - " }", - " },", - " create: function(context) {", - " return {};", - " }", - "};" - ].join("\n"), - errors: [{ - messageId: "incorrectUrl", - data: { - expected: "https://eslint.org/docs/rules/", - url: "http://example.com/wrong-url" - }, - line: 4, - column: 18 - }] - } - ] -}); diff --git a/tools/internal-rules/consistent-docs-url.js b/tools/internal-rules/consistent-docs-url.js deleted file mode 100644 index 052fe55f28a..00000000000 --- a/tools/internal-rules/consistent-docs-url.js +++ /dev/null @@ -1,119 +0,0 @@ -/** - * @fileoverview Internal rule to enforce meta.docs.url conventions. - * @author Patrick McElhaney - */ - -"use strict"; - -const path = require("path"); - -//------------------------------------------------------------------------------ -// Helpers -//------------------------------------------------------------------------------ - -/** - * Gets the property of the Object node passed in that has the name specified. - * @param {string} property Name of the property to return. - * @param {ASTNode} node The ObjectExpression node. - * @returns {ASTNode} The Property node or null if not found. - */ -function getPropertyFromObject(property, node) { - const properties = node.properties; - - if (!Array.isArray(properties)) { - - // if properties is not an array, "internal-no-invalid-meta" will already report this. - return null; - } - - for (let i = 0; i < properties.length; i++) { - if (properties[i].key.name === property) { - return properties[i]; - } - } - - return null; -} - -/** - * Verifies that the meta.docs.url property is present and has the correct value. - * @param {RuleContext} context The ESLint rule context. - * @param {ASTNode} exportsNode ObjectExpression node that the rule exports. - * @returns {void} - */ -function checkMetaDocsUrl(context, exportsNode) { - if (exportsNode.type !== "ObjectExpression") { - - // if the exported node is not the correct format, "internal-no-invalid-meta" will already report this. - return; - } - - const metaProperty = getPropertyFromObject("meta", exportsNode); - const metaDocs = metaProperty && getPropertyFromObject("docs", metaProperty.value); - const metaDocsUrl = metaDocs && getPropertyFromObject("url", metaDocs.value); - - if (!metaDocs) { - context.report({ - node: metaProperty, - messageId: "missingMetaDocs" - }); - return; - } - - if (!metaDocsUrl) { - context.report({ - node: metaDocs, - messageId: "missingMetaDocsUrl" - }); - return; - } - - const ruleId = path.basename(context.getFilename().replace(/.js$/u, "")); - const expected = `https://eslint.org/docs/rules/${ruleId}`; - const url = metaDocsUrl.value.value; - - if (url !== expected) { - context.report({ - node: metaDocsUrl.value, - messageId: "incorrectUrl", - data: { expected, url } - }); - } - -} - -//------------------------------------------------------------------------------ -// Rule Definition -//------------------------------------------------------------------------------ - -module.exports = { - meta: { - docs: { - description: "enforce correct conventions of `meta.docs.url` property in core rules", - category: "Internal", - recommended: false - }, - type: "suggestion", - schema: [], - messages: { - missingMetaDocs: "Rule is missing a meta.docs property.", - missingMetaDocsUrl: "Rule is missing a meta.docs.url property.", - incorrectUrl: 'Incorrect url. Expected "{{ expected }}" but got "{{ url }}".' - } - }, - - create(context) { - return { - AssignmentExpression(node) { - if (node.left && - node.right && - node.left.type === "MemberExpression" && - node.left.object.name === "module" && - node.left.property.name === "exports") { - - checkMetaDocsUrl(context, node.right); - } - } - }; - } -};