Skip to content

Commit

Permalink
feat!: change test-case-property-ordering to add supports languageOpt…
Browse files Browse the repository at this point in the history
…ions (#406)

* feat: change test-case-property-ordering to add supports languageOptions

fixes #402

Signed-off-by: 唯然 <[email protected]>

* Update test-case-property-ordering.js

* chore: apply eslint --fix

---------

Signed-off-by: 唯然 <[email protected]>
  • Loading branch information
aladdin-add authored Apr 10, 2024
1 parent ff28db3 commit 0dd0857
Show file tree
Hide file tree
Showing 14 changed files with 42 additions and 19 deletions.
7 changes: 4 additions & 3 deletions lib/rules/test-case-property-ordering.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ module.exports = {
'output',
'options',
'parser',
'parserOptions',
'globals',
'env',
'languageOptions', // flat-mode only
'parserOptions', // eslintrc-mode only
'globals', // eslintrc-mode only
'env', // eslintrc-mode only
'errors',
];
const sourceCode = context.sourceCode || context.getSourceCode(); // TODO: just use context.sourceCode when dropping eslint < v9
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/rules/meta-property-ordering.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,13 @@ ruleTester.run('test-case-property-ordering', rule, {
},
create() {},
};`,
languageOptions: { sourceType: 'module' },
errors: [
{
messageId: 'inconsistentOrder',
data: { order: ['type', 'docs', 'fixable'].join(', ') },
},
],
languageOptions: { sourceType: 'module' },
},
{
code: `
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/rules/no-identical-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ ruleTester.run('no-identical-tests', rule, {
});
}
`,
errors: [{ messageId: 'identical', type: 'TemplateLiteral' }],
languageOptions: { ecmaVersion: 2015 },
errors: [{ messageId: 'identical', type: 'TemplateLiteral' }],
},
],
});
2 changes: 1 addition & 1 deletion tests/lib/rules/no-missing-message-ids.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,14 +323,14 @@ ruleTester.run('no-missing-message-ids', rule, {
}
};
`,
languageOptions: { sourceType: 'module' },
errors: [
{
messageId: 'missingMessage',
data: { messageId: 'foo' },
type: 'Literal',
},
],
languageOptions: { sourceType: 'module' },
},
{
// Helper function with messageId parameter, inside rule, with missing messageId due to parameter reassignment.
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/rules/no-unused-message-ids.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,14 +325,14 @@ ruleTester.run('no-unused-message-ids', rule, {
}
};
`,
languageOptions: { sourceType: 'module' },
errors: [
{
messageId: 'unusedMessage',
data: { messageId: 'foo' },
type: 'Property',
},
],
languageOptions: { sourceType: 'module' },
},
{
// `meta` / `create` in variables
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/rules/prefer-message-ids.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ ruleTester.run('prefer-message-ids', rule, {
}
};
`,
errors: [{ messageId: 'foundMessage', type: 'Property' }],
languageOptions: { sourceType: 'module' },
errors: [{ messageId: 'foundMessage', type: 'Property' }],
},
{
// With message in variable.
Expand Down
8 changes: 4 additions & 4 deletions tests/lib/rules/prefer-object-rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,27 +143,27 @@ ruleTester.run('prefer-object-rule', rule, {
return { Program() { context.report() } };
}};
`,
errors: [{ messageId: 'preferObject', line: 2, column: 24 }],
languageOptions: { sourceType: 'module' },
errors: [{ messageId: 'preferObject', line: 2, column: 24 }],
},
{
code: 'export default function create(context) { return {}; };',
output: 'export default {create(context) { return {}; }};',
errors: [{ messageId: 'preferObject', line: 1, column: 16 }],
languageOptions: { sourceType: 'module' },
errors: [{ messageId: 'preferObject', line: 1, column: 16 }],
},
{
code: 'export default (context) => { return {}; };',
output: 'export default {create: (context) => { return {}; }};',
errors: [{ messageId: 'preferObject', line: 1, column: 16 }],
languageOptions: { sourceType: 'module' },
errors: [{ messageId: 'preferObject', line: 1, column: 16 }],
},
{
code: 'const rule = (context) => { return {}; }; export default rule;',
output:
'const rule = {create: (context) => { return {}; }}; export default rule;',
errors: [{ messageId: 'preferObject', line: 1, column: 14 }],
languageOptions: { sourceType: 'module' },
errors: [{ messageId: 'preferObject', line: 1, column: 14 }],
},
],
});
2 changes: 1 addition & 1 deletion tests/lib/rules/require-meta-docs-description.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ ruleTester.run('require-meta-docs-description', rule, {
};
`,
output: null,
errors: [{ messageId: 'missing', type: 'ObjectExpression' }],
languageOptions: { sourceType: 'module' },
errors: [{ messageId: 'missing', type: 'ObjectExpression' }],
},
{
code: `
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/rules/require-meta-docs-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -733,8 +733,8 @@ url: "plugin-name/test.md"
pattern: 'plugin-name/{{ name }}.md',
},
],
errors: [{ messageId: 'missing', type: 'ObjectExpression' }],
languageOptions: { sourceType: 'module' },
errors: [{ messageId: 'missing', type: 'ObjectExpression' }],
},
{
// TypeScript
Expand All @@ -756,8 +756,8 @@ url: "plugin-name/test.md"
}
`,
options: [{ pattern: 'plugin-name/{{ name }}.md' }],
errors: [{ messageId: 'missing', type: 'ObjectExpression' }],
languageOptions: { sourceType: 'module' },
errors: [{ messageId: 'missing', type: 'ObjectExpression' }],
},
{
filename: 'test.js',
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/rules/require-meta-fixable.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,8 @@ ruleTester.run('require-meta-fixable', rule, {
create(context) { context.report({node, message, fix: foo}); }
};
`,
errors: [{ messageId: 'missing', type: 'ObjectExpression' }],
languageOptions: { sourceType: 'module' },
errors: [{ messageId: 'missing', type: 'ObjectExpression' }],
},
{
code: `
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/rules/require-meta-has-suggestions.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ ruleTester.run('require-meta-has-suggestions', rule, {
};
`,
output: null,
languageOptions: { sourceType: 'module' },
errors: [
{
messageId: 'shouldBeSuggestable',
Expand All @@ -301,7 +302,6 @@ ruleTester.run('require-meta-has-suggestions', rule, {
endColumn: 78,
},
],
languageOptions: { sourceType: 'module' },
},
{
// Reports suggestions, no hasSuggestions property, violation should be on `meta` object, empty meta object.
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/rules/require-meta-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ schema: []
};
`,
output: null,
languageOptions: { sourceType: 'module' },
errors: [
{
messageId: 'missing',
Expand All @@ -275,7 +276,6 @@ schema: []
],
},
],
languageOptions: { sourceType: 'module' },
},
{
code: `
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/rules/require-meta-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ ruleTester.run('require-meta-type', rule, {
create(context) {}
};
`,
errors: [{ messageId: 'missing', type: 'ObjectExpression' }],
languageOptions: { sourceType: 'module' },
errors: [{ messageId: 'missing', type: 'ObjectExpression' }],
},
{
code: `
Expand Down
22 changes: 22 additions & 0 deletions tests/lib/rules/test-case-property-ordering.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,5 +214,27 @@ ruleTester.run('test-case-property-ordering', rule, {
},
],
},
{
code: `
new RuleTester().run('foo', bar, {
valid: [
{\ncode: "foo",\noutput: "",\nerrors: ["baz"],\nlanguageOptions: "",\n},
]
});
`,
output: `
new RuleTester().run('foo', bar, {
valid: [
{\ncode: "foo",\noutput: "",\nlanguageOptions: "",\nerrors: ["baz"],\n},
]
});
`,
errors: [
{
message:
'The properties of a test case should be placed in a consistent order: [code, output, languageOptions, errors].',
},
],
},
],
});

0 comments on commit 0dd0857

Please sign in to comment.