diff --git a/.eslintrc.js b/.eslintrc.js
index 668bc2747c54..a7e0f1153d88 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/.github/ISSUE_TEMPLATE/BUG_REPORT.md b/.github/ISSUE_TEMPLATE/BUG_REPORT.md
index 9b46d2944f2b..b368e5009c4f 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?**
diff --git a/.github/ISSUE_TEMPLATE/NEW_SYNTAX.md b/.github/ISSUE_TEMPLATE/NEW_SYNTAX.md
new file mode 100644
index 000000000000..e03cb6e11bdc
--- /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?**
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 6ba0bdc384be..b1972878e940 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
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f4a316be0f9d..bd7fb6b5e9a7 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)
diff --git a/README.md b/README.md
index 68982812e3b0..804310d8c1fb 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
diff --git a/docs/rules/no-eq-null.md b/docs/rules/no-eq-null.md
index df8f97a5ebad..7b0f5df142a7 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.
diff --git a/docs/rules/space-after-keywords.md b/docs/rules/space-after-keywords.md
index af1b739fe0e8..7f6182b227a7 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 8adf593a6c7e..077c9a322faf 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 024eb3c9586a..ff55f7f5effb 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 bf9b70d12db4..244fb0e98559 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:
diff --git a/lib/rules/consistent-return.js b/lib/rules/consistent-return.js
index a250430cb766..0e20209af56b 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/package.json b/package.json
index 8fabe0a68f55..ea08a90ef652 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": {
@@ -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",
@@ -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/lib/rules/consistent-return.js b/tests/lib/rules/consistent-return.js
index 53781ea423dc..16a1ed97a193 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
}
]
}
diff --git a/tests/lib/rules/unicode-bom.js b/tests/lib/rules/unicode-bom.js
index 0b94a6902910..62abee698708 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
+
+ }]
}
]
});
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 4b3d3a05b671..000000000000
--- 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 052fe55f28a8..000000000000
--- 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);
- }
- }
- };
- }
-};
|