8000 Chore: Simplify internal `no-invalid-meta` rule (#14842) · eslint/eslint@ed007c8 · GitHub
[go: up one dir, main page]

Skip to content

Commit ed007c8

Browse files
authored
Chore: Simplify internal no-invalid-meta rule (#14842)
1 parent d53d906 commit ed007c8

File tree

3 files changed

+5
-110
lines changed

3 files changed

+5
-110
lines changed

.eslintrc.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,13 @@ module.exports = {
6666
rules: {
6767
"eslint-plugin/consistent-output": "error",
6868
"eslint-plugin/no-deprecated-context-methods": "error",
69+
"eslint-plugin/no-only-tests": "error",
6970
"eslint-plugin/prefer-output-null": "error",
7071
"eslint-plugin/prefer-placeholders": "error",
72+
"eslint-plugin/prefer-replace-text": "error",
7173
"eslint-plugin/report-message-format": ["error", "[^a-z].*\\.$"],
7274
"eslint-plugin/require-meta-docs-description": "error",
75+
"eslint-plugin/require-meta-schema": "error",
7376
"eslint-plugin/require-meta-type": "error",
7477
"eslint-plugin/test-case-property-ordering": "error",
7578
"eslint-plugin/test-case-shorthand-strings": "error",
@@ -80,6 +83,7 @@ module.exports = {
8083
files: ["lib/rules/*", "tools/internal-rules/*"],
8184
excludedFiles: ["index.js"],
8285
rules: {
86+
"eslint-plugin/prefer-object-rule": "error",
8387
"internal-rules/no-invalid-meta": "error",
8488
"internal-rules/consistent-meta-messages": "error"
8589
}

tests/tools/internal-rules/no-invalid-meta.js

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -96,20 +96,6 @@ ruleTester.run("no-invalid-meta", rule, {
9696
].join("\n")
9797
],
9898
invalid: [
99-
{
100-
code: [
101-
"module.exports = function(context) {",
102-
" return {",
103-
" Program: function(node) {}",
104-
" };",
105-
"};"
106-
].join("\n"),
107-
errors: [{
108-
messageId: "incorrectExport",
109-
line: 1,
110-
column: 18
111-
}]
112-
},
11399
{
114100
code: [
115101
"module.exports = {",
@@ -164,30 +150,6 @@ ruleTester.run("no-invalid-meta", rule, {
164150
column: 5
165151
}]
166152
},
167-
{
168-
code: [
169-
"module.exports = {",
170-
" meta: {",
171-
" docs: {",
172-
" category: 'Internal',",
173-
" recommended: false",
174-
" },",
175-
" schema: []",
176-
" },",
177-
178-
" create: function(context) {",
179-
" return {",
180-
" Program: function(node) {}",
181-
" };",
182-
" }",
183-
"};"
184-
].join("\n"),
185-
errors: [{
186-
messageId: "missingMetaDocsDescription",
187-
line: 2,
188-
column: 5
189-
}]
190-
},
191153
{
192154
code: [
193155
"module.exports = {",
@@ -236,30 +198,6 @@ ruleTester.run("no-invalid-meta", rule, {
236198
column: 5
237199
}]
238200
},
239-
{
240-
code: [
241-
"module.exports = {",
242-
" meta: {",
243-
" docs: {",
244-
" description: 'some rule',",
245-
" category: 'Internal',",
246-
" recommended: false",
247-
" }",
248-
" },",
249-
250-
" create: function(context) {",
251-
" return {",
252-
" Program: function(node) {}",
253-
" };",
254-
" }",
255-
"};"
256-
].join("\n"),
257-
errors: [{
258-
messageId: "missingMetaSchema",
259-
line: 2,
260-
column: 5
261-
}]
262-
},
263201
{
264202
code: "",
265203
errors: [{

tools/internal-rules/no-invalid-meta.js

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,6 @@ function hasMetaDocs(metaPropertyNode) {
5050
return Boolean(getPropertyFromObject("docs", metaPropertyNode.value));
5151
}
5252

53-
/**
54-
* Whether this `meta` ObjectExpression has a `docs.description` property defined or not.
55-
* @param {ASTNode} metaPropertyNode The `meta` ObjectExpression for this rule.
56-
* @returns {boolean} `true` if a `docs.description` property exists.
57-
*/
58-
function hasMetaDocsDescription(metaPropertyNode) {
59-
const metaDocs = getPropertyFromObject("docs", metaPropertyNode.value);
60-
61-
return metaDocs && getPropertyFromObject("description", metaDocs.value);
62-
}
63-
6453
/**
6554
* Whether this `meta` ObjectExpression has a `docs.category` property defined or not.
6655
* @param {ASTNode} metaPropertyNode The `meta` ObjectExpression for this rule.
@@ -83,15 +72,6 @@ function hasMetaDocsRecommended(metaPropertyNode) {
8372
return metaDocs && getPropertyFromObject("recommended", metaDocs.value);
8473
}
8574

86-
/**
87-
* Whether this `meta` ObjectExpression has a `schema` property defined or not.
88-
* @param {ASTNode} metaPropertyNode The `meta` ObjectExpression for this rule.
89-
* @returns {boolean} `true` if a `schema` property exists.
90-
*/
91-
function hasMetaSchema(metaPropertyNode) {
92-
return getPropertyFromObject("schema", metaPropertyNode.value);
93-
}
94-
9575
/**
9676
* Checks the validity of the meta definition of this rule and reports any errors found.
9777
* @param {RuleContext} context The ESLint rule context.
@@ -111,35 +91,16 @@ function checkMetaValidity(context, exportsNode) {
11191
return;
11292
}
11393

114-
if (!hasMetaDocsDescription(metaProperty)) {
115-
context.report({ node: metaProperty, messageId: "missingMetaDocsDescription" });
116-
return;
117-
}
118-
11994
if (!hasMetaDocsCategory(metaProperty)) {
12095
context.report({ node: metaProperty, messageId: "missingMetaDocsCategory" });
12196
return;
12297
}
12398

12499
if (!hasMetaDocsRecommended(metaProperty)) {
125100
context.report({ node: metaProperty, messageId: "missingMetaDocsRecommended" });
126-
return;
127-
}
128-
129-
if (!hasMetaSchema(metaProperty)) {
130-
context.report({ node: metaProperty, messageId: "missingMetaSchema" });
131101
}
132102
}
133103

134-
/**
135-
* Whether this node is the correct format for a rule definition or not.
136-
* @param {ASTNode} node node that the rule exports.
137-
* @returns {boolean} `true` if the exported node is the correct format for a rule definition
138-
*/
139-
function isCorrectExportsFormat(node) {
140-
return node.type === "ObjectExpression";
141-
}
142-
143104
//------------------------------------------------------------------------------
144105
// Rule Definition
145106
//------------------------------------------------------------------------------
@@ -156,12 +117,9 @@ module.exports = {
156117
messages: {
157118
missingMeta: "Rule is missing a meta property.",
158119
missingMetaDocs: "Rule is missing a meta.docs property.",
159-
missingMetaDocsDescription: "Rule is missing a meta.docs.description property.",
160120
missingMetaDocsCategory: "Rule is missing a meta.docs.category property.",
161121
missingMetaDocsRecommended: "Rule is missing a meta.docs.recommended property.",
162-
missingMetaSchema: "Rule is missing a meta.schema property.",
163-
noExport: "Rule does not export anything. Make sure rule exports an object according to new rule format.",
164-
incorrectExport: "Rule does not export an Object. Make sure the rule follows the new rule format."
122+
noExport: "Rule does not export anything. Make sure rule exports an object according to new rule format."
165123
}
166124
},
167125

@@ -186,11 +144,6 @@ module.exports = {
186144
node,
187145
messageId: "noExport"
188146
});
189-
} else if (!isCorrectExportsFormat(exportsNode)) {
190-
context.report({
191-
node: exportsNode,
192-
messageId: "incorrectExport"
193-
});
194147
} else {
195148
checkMetaValidity(context, exportsNode);
196149
}

0 commit comments

Comments
 (0)
0