Skip to content

Commit e785e42

Browse files
committed
Make scoped custom rule package identifiers work with the --rules parameter (fixes #449).
1 parent e7939f7 commit e785e42

File tree

6 files changed

+34
-1
lines changed

6 files changed

+34
-1
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ build/Release
2828
node_modules
2929
# Keep it for test
3030
!test/custom-rules/relative-to-cwd/node_modules
31+
!test/custom-rules/scoped-package/node_modules
3132

3233
# Optional npm cache directory
3334
.npm

markdownlint.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ program.parse(process.argv);
199199

200200
function tryResolvePath(filepath) {
201201
try {
202-
if (path.basename(filepath) === filepath && path.extname(filepath) === '') {
202+
if ((path.basename(filepath) === filepath || filepath.startsWith('@')) && path.extname(filepath) === '') {
203203
// Looks like a package name, resolve it relative to cwd
204204
// Get list of directories, where requested module can be.
205205
let paths = Module._nodeModulePaths(processCwd);

test/custom-rules/scoped-package/node_modules/@scoped/custom-rule/package.json

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/custom-rules/scoped-package/node_modules/@scoped/custom-rule/scoped-rule.cjs

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Scoped Test

test/test.js

+15
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,21 @@ test('Custom rule from node_modules package loaded relative to cwd', async t =>
535535
}
536536
});
537537

538+
test('Custom rule with scoped package name via --rules', async t => {
539+
try {
540+
await execa(path.resolve('..', 'markdownlint.js'), ['--rules', '@scoped/custom-rule', 'scoped-test.md'], {
541+
cwd: path.join(__dirname, 'custom-rules', 'scoped-package'),
542+
stripFinalNewline: false
543+
});
544+
t.fail();
545+
} catch (error) {
546+
const expected = ['scoped-test.md:1 scoped-rule Scoped rule', ''].join('\n');
547+
t.is(error.stdout, '');
548+
t.is(error.stderr, expected);
549+
t.is(error.exitCode, 1);
550+
}
551+
});
552+
538553
test('Custom rule from package loaded', async t => {
539554
try {
540555
const input = '# Input\n';

0 commit comments

Comments
 (0)