Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for variation of scoped plugin name #256

Merged
merged 1 commit into from
Nov 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/package-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export function getPluginPrefix(path: string): string {
}
return pluginPackageJson.name.endsWith('/eslint-plugin')
? pluginPackageJson.name.split('/')[0] // Scoped plugin name like @my-scope/eslint-plugin.
: pluginPackageJson.name.replace('eslint-plugin-', ''); // Unscoped name like eslint-plugin-foo.
: pluginPackageJson.name.replace('eslint-plugin-', ''); // Unscoped name like eslint-plugin-foo or scoped name like @my-scope/eslint-plugin-foo.
}

/**
Expand Down
22 changes: 22 additions & 0 deletions test/lib/generate/__snapshots__/package-json-test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,28 @@ exports[`generate (package.json) Scoped plugin name determines the correct plugi
"
`;

exports[`generate (package.json) Scoped plugin with custom plugin name determines the correct plugin prefix 1`] = `
"<!-- begin auto-generated rules list -->

💼 Configurations enabled in.\\
✅ Set in the \`recommended\` configuration.

| Name | Description | 💼 |
| :----------------------------- | :------------ | :- |
| [no-foo](docs/rules/no-foo.md) | disallow foo. | ✅ |

<!-- end auto-generated rules list -->"
`;

exports[`generate (package.json) Scoped plugin with custom plugin name determines the correct plugin prefix 2`] = `
"# Disallow foo (\`@my-scope/foo/no-foo\`)

💼 This rule is enabled in the ✅ \`recommended\` config.

<!-- end auto-generated rule header -->
"
`;

exports[`generate (package.json) plugin entry point in JSON format generates the documentation 1`] = `
"<!-- begin auto-generated rules list -->

Expand Down
42 changes: 42 additions & 0 deletions test/lib/generate/package-json-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,48 @@ describe('generate (package.json)', function () {
});
});

describe('Scoped plugin with custom plugin name', function () {
beforeEach(function () {
mockFs({
'package.json': JSON.stringify({
name: '@my-scope/eslint-plugin-foo',
exports: 'index.js',
type: 'module',
}),

'index.js': `
export default {
rules: {
'no-foo': {
meta: { docs: { description: 'disallow foo.' }, },
create(context) {}
},
},
configs: {
'recommended': { rules: { '@my-scope/foo/no-foo': 'error', } }
}
};`,

'README.md':
'<!-- begin auto-generated rules list --><!-- end auto-generated rules list -->',

'docs/rules/no-foo.md': '',

// Needed for some of the test infrastructure to work.
node_modules: mockFs.load(PATH_NODE_MODULES),
});
});
afterEach(function () {
mockFs.restore();
jest.resetModules();
});
it('determines the correct plugin prefix', async function () {
await generate('.');
expect(readFileSync('README.md', 'utf8')).toMatchSnapshot();
expect(readFileSync('docs/rules/no-foo.md', 'utf8')).toMatchSnapshot();
});
});

describe('No configs found', function () {
beforeEach(function () {
mockFs({
Expand Down