Skip to content

Commit

Permalink
add test cases for 3rd-party plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
mizdra committed Sep 25, 2024
1 parent c9d9114 commit 160a504
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 17 deletions.
61 changes: 44 additions & 17 deletions src/__snapshots__/core.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,20 @@ exports[`Core > disablePerLine 1`] = `
let a = 1;"
`;

exports[`Core > fixes problems with legacy config and 3rd-party plugins 1`] = `
"// eslint-disable-next-line test/ban-nullish-coalescing-operator
// eslint-disable-next-line test/ban-nullish-coalescing-operator
// eslint-disable-next-line test/ban-nullish-coalescing-operator
// eslint-disable-next-line test/ban-nullish-coalescing-operator
// eslint-disable-next-line test/ban-nullish-coalescing-operator
// eslint-disable-next-line test/ban-nullish-coalescing-operator
// eslint-disable-next-line test/ban-nullish-coalescing-operator
// eslint-disable-next-line test/ban-nullish-coalescing-operator
// eslint-disable-next-line test/ban-nullish-coalescing-operator
// eslint-disable-next-line test/ban-nullish-coalescing-operator
2 ?? 2;"
`;

exports[`Core > flat config 1`] = `
[
{
Expand Down Expand Up @@ -194,6 +208,17 @@ exports[`Core > lint > returns lint results 1`] = `
],
"warningCount": 0,
},
{
"errorCount": 1,
"filePath": "<fixture>/src/ban-nullish-coalescing-operator.js",
"messages": [
{
"ruleId": "test/ban-nullish-coalescing-operator",
"severity": 2,
},
],
"warningCount": 0,
},
{
"errorCount": 1,
"filePath": "<fixture>/src/import-order.js",
Expand Down Expand Up @@ -270,22 +295,24 @@ exports[`Core > printDetailsOfResults 1`] = `
`;
exports[`Core > printSummaryOfResults 1`] = `
"- 7 files (0 file passed, 7 files failed) checked.
- 18 problems (17 errors, 1 warning) found.
╔═════════════════════════════╤═══════╤═════════╤════════════╤═════════════════╗
║ Rule │ Error │ Warning │ is fixable │ has suggestions ║
╟─────────────────────────────┼───────┼─────────┼────────────┼─────────────────╢
║ arrow-body-style │ 12 │ 0 │ 12 │ 0 ║
╟─────────────────────────────┼───────┼─────────┼────────────┼─────────────────╢
║ ban-exponentiation-operator │ 1 │ 0 │ 0 │ 0 ║
╟─────────────────────────────┼───────┼─────────┼────────────┼─────────────────╢
║ import/order │ 1 │ 0 │ 0 │ 0 ║
╟─────────────────────────────┼───────┼─────────┼────────────┼─────────────────╢
║ no-unsafe-negation │ 1 │ 0 │ 0 │ 1 ║
╟─────────────────────────────┼───────┼─────────┼────────────┼─────────────────╢
║ no-unused-vars │ 1 │ 0 │ 0 │ 0 ║
╟─────────────────────────────┼───────┼─────────┼────────────┼─────────────────╢
║ ]8;;https://example.comprefer-const]8;; │ 1 │ 1 │ 2 │ 0 ║
╚═════════════════════════════╧═══════╧═════════╧════════════╧═════════════════╝
"- 8 files (0 file passed, 8 files failed) checked.
- 19 problems (18 errors, 1 warning) found.
╔══════════════════════════════════════╤═══════╤═════════╤════════════╤═════════════════╗
║ Rule │ Error │ Warning │ is fixable │ has suggestions ║
╟──────────────────────────────────────┼───────┼─────────┼────────────┼─────────────────╢
║ arrow-body-style │ 12 │ 0 │ 12 │ 0 ║
╟──────────────────────────────────────┼───────┼─────────┼────────────┼─────────────────╢
║ ban-exponentiation-operator │ 1 │ 0 │ 0 │ 0 ║
╟──────────────────────────────────────┼───────┼─────────┼────────────┼─────────────────╢
║ test/ban-nullish-coalescing-operator │ 1 │ 0 │ 0 │ 0 ║
╟──────────────────────────────────────┼───────┼─────────┼────────────┼─────────────────╢
║ import/order │ 1 │ 0 │ 0 │ 0 ║
╟──────────────────────────────────────┼───────┼─────────┼────────────┼─────────────────╢
║ no-unsafe-negation │ 1 │ 0 │ 0 │ 1 ║
╟──────────────────────────────────────┼───────┼─────────┼────────────┼─────────────────╢
║ no-unused-vars │ 1 │ 0 │ 0 │ 0 ║
╟──────────────────────────────────────┼───────┼─────────┼────────────┼─────────────────╢
║ ]8;;https://example.comprefer-const]8;; │ 1 │ 1 │ 2 │ 0 ║
╚══════════════════════════════════════╧═══════╧═════════╧════════════╧═════════════════╝
"
`;
37 changes: 37 additions & 0 deletions src/core.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ const iff = await createIFF({
'src/ban-exponentiation-operator.js': dedent`
2 ** 2;
`,
'src/ban-nullish-coalescing-operator.js': dedent`
2 ?? 2;
`,
'src/no-unused-vars.js': dedent`
const a = 1;
`,
Expand All @@ -91,18 +94,47 @@ const iff = await createIFF({
'src/no-unsafe-negation.js': dedent`
if (!key in object) {}
`,
'node_modules/eslint-plugin-test/package.json': dedent`
{
"name": "eslint-plugin-test",
"version": "1.0.0",
"main": "index.js"
}
`,
'node_modules/eslint-plugin-test/index.js': dedent`
module.exports = {
rules: {
'ban-nullish-coalescing-operator': {
create(context) {
return {
LogicalExpression: (node) => {
if (node.operator === '??') {
context.report({
node,
message: 'Ban nullish coalescing operator',
});
}
},
};
},
},
},
};
`,
'.eslintrc.js': dedent`
module.exports = {
root: true,
parserOptions: {
ecmaVersion: 2021,
sourceType: 'module',
},
plugins: ['test'],
overrides: [
{ files: ['prefer-const.js'], rules: { 'prefer-const': 'error' } },
{ files: ['arrow-body-style.js'], rules: { 'arrow-body-style': ['error', 'always'] } },
{ files: ['import-order.js'], rules: { 'import/order': 'error' } },
{ files: ['ban-exponentiation-operator.js'], rules: { 'ban-exponentiation-operator': 'error' } },
{ files: ['ban-nullish-coalescing-operator.js'], rules: { 'test/ban-nullish-coalescing-operator': 'error' } },
{
files: ['no-unused-vars.js'],
rules: { 'no-unused-vars': ['error', { varsIgnorePattern: '^_' }] },
Expand Down Expand Up @@ -312,4 +344,9 @@ describe('Core', () => {
expect(await readFile(iff.paths['src/index.jsx'], 'utf-8')).toMatchSnapshot();
expect(await readFile(iff.paths['src/.index.js'], 'utf-8')).toMatchSnapshot();
});
test('fixes problems with legacy config and 3rd-party plugins', async () => {
const results = await core.lint();
await core.disablePerLine(results, ['test/ban-nullish-coalescing-operator']);
expect(await readFile(iff.paths['src/ban-nullish-coalescing-operator.js'], 'utf-8')).toMatchSnapshot();
});
});

0 comments on commit 160a504

Please sign in to comment.