Skip to content

Commit

Permalink
Make scoped custom rule package identifiers work with the --rules par…
Browse files Browse the repository at this point in the history
…ameter (fixes #449).
  • Loading branch information
DavidAnson committed Jan 28, 2024
1 parent e7939f7 commit e785e42
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ build/Release
node_modules
# Keep it for test
!test/custom-rules/relative-to-cwd/node_modules
!test/custom-rules/scoped-package/node_modules

# Optional npm cache directory
.npm
Expand Down
2 changes: 1 addition & 1 deletion markdownlint.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ program.parse(process.argv);

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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/custom-rules/scoped-package/scoped-test.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Scoped Test
15 changes: 15 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,21 @@ test('Custom rule from node_modules package loaded relative to cwd', async t =>
}
});

test('Custom rule with scoped package name via --rules', async t => {
try {
await execa(path.resolve('..', 'markdownlint.js'), ['--rules', '@scoped/custom-rule', 'scoped-test.md'], {
cwd: path.join(__dirname, 'custom-rules', 'scoped-package'),
stripFinalNewline: false
});
t.fail();
} catch (error) {
const expected = ['scoped-test.md:1 scoped-rule Scoped rule', ''].join('\n');
t.is(error.stdout, '');
t.is(error.stderr, expected);
t.is(error.exitCode, 1);
}
});

test('Custom rule from package loaded', async t => {
try {
const input = '# Input\n';
Expand Down

0 comments on commit e785e42

Please sign in to comment.