Skip to content

Commit 6a09dbe

Browse files
authored
fix: handle different rule file extensions like .ts in require-meta-docs-url rule (#224)
1 parent 0fc8c45 commit 6a09dbe

File tree

2 files changed

+71
-1
lines changed

2 files changed

+71
-1
lines changed

Diff for: lib/rules/require-meta-docs-url.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ module.exports = {
4949
const options = context.options[0] || {};
5050
const sourceCode = context.getSourceCode();
5151
const filename = context.getFilename();
52-
const ruleName = filename === '<input>' ? undefined : path.basename(filename, '.js');
52+
const ruleName = filename === '<input>' ? undefined : path.basename(filename, path.extname(filename));
5353
const expectedUrl = !options.pattern || !ruleName
5454
? undefined
5555
: options.pattern.replace(/{{\s*name\s*}}/g, ruleName);

Diff for: tests/lib/rules/require-meta-docs-url.js

+70
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,17 @@ tester.run('require-meta-docs-url', rule, {
6666
pattern: 'path/to/{{name}}.md',
6767
}],
6868
},
69+
{
70+
// CJS file extension
71+
filename: 'test-rule.cjs',
72+
code: `
73+
module.exports = {
74+
meta: {docs: {url: "path/to/test-rule.md"}},
75+
create() {}
76+
}
77+
`,
78+
options: [{ pattern: 'path/to/{{name}}.md' }],
79+
},
6980
{
7081
// ESM
7182
filename: 'test-rule',
@@ -80,6 +91,18 @@ tester.run('require-meta-docs-url', rule, {
8091
}],
8192
parserOptions: { sourceType: 'module' },
8293
},
94+
{
95+
// TypeScript
96+
filename: 'rules/test-rule.ts',
97+
code: `
98+
export default {
99+
meta: {docs: {url: "path/to/test-rule.md"}},
100+
create() {}
101+
}
102+
`,
103+
options: [{ pattern: 'path/to/{{name}}.md' }],
104+
parserOptions: { sourceType: 'module' },
105+
},
83106
{
84107
// `url` in variable.
85108
filename: 'test-rule',
@@ -542,6 +565,30 @@ tester.run('require-meta-docs-url', rule, {
542565
docs: {
543566
url: "plugin-name/test.md"
544567
}
568+
},
569+
create() {}
570+
}
571+
`,
572+
options: [{
573+
pattern: 'plugin-name/{{ name }}.md',
574+
}],
575+
errors: [{ messageId: 'missing', type: 'ObjectExpression' }],
576+
},
577+
{
578+
// CJS file extension
579+
filename: 'test.cjs',
580+
code: `
581+
module.exports = {
582+
meta: {},
583+
create() {}
584+
}
585+
`,
586+
output: `
587+
module.exports = {
588+
meta: {
589+
docs: {
590+
url: "plugin-name/test.md"
591+
}
545592
},
546593
create() {}
547594
}
@@ -576,6 +623,29 @@ url: "plugin-name/test.md"
576623
parserOptions: { sourceType: 'module' },
577624
errors: [{ messageId: 'missing', type: 'ObjectExpression' }],
578625
},
626+
{
627+
// TypeScript
628+
filename: 'test.ts',
629+
code: `
630+
export default {
631+
meta: {},
632+
create() {}
633+
}
634+
`,
635+
output: `
636+
export default {
637+
meta: {
638+
docs: {
639+
url: "plugin-name/test.md"
640+
}
641+
},
642+
create() {}
643+
}
644+
`,
645+
options: [{ pattern: 'plugin-name/{{ name }}.md' }],
646+
parserOptions: { sourceType: 'module' },
647+
errors: [{ messageId: 'missing', type: 'ObjectExpression' }],
648+
},
579649
{
580650
filename: 'test.js',
581651
code: `

0 commit comments

Comments
 (0)