deno-lint: cli ignores path
Hope you don't mind me submitting 2 separate issues at once, but I don't think this is related to #630.
It seems the denolint cli ignores the path parameter and lints everything recursively, starting at the cwd. Example where I point it at a file with a single script, and it lints a second script in the current directory anyway:
~$ tree
.
├── main.js
└── test
└── main2.js
1 directory, 2 files
~$ npx denolint test
error[require-await]: Async function 'main' has no 'await' expression.
-->~/test/main2.js:2:1
|
2 | / async function main() {
3 | | console.log('hello world!');
4 | | }
| |_^
|
= help: Remove 'async' keyword from the function or use 'await' expression inside.
error[require-await]: Async function 'main' has no 'await' expression.
--> ~/test/main.js:2:1
|
2 | / async function main() {
3 | | console.log('hello world!');
4 | | }
| |_^
|
= help: Remove 'async' keyword from the function or use 'await' expression inside.
You can create a file .eslintignore with file paths or patterns to ignore as a workaround. It is sufficient for the use case of checking the whole project.
UPDATE: In the meanwhile, .denolintignore is tried too. Source code directives for disabling are eslint-disable (only for the command-line tool) and eslint-disable-next-line. Which means there's just eslint-disable-next-line for the practical usage. Weird decision about the eslint-disable.
@prantlf - one interesting use case, not covered by the above .eslintignore workaround, is linting one specific file at a time. This is especially useful when integrating denolint with editors so that the current file can be automatically linted on save.
@hadriann, yes, if you integrate denolint to an editor, git hook or other tool, which lints a file selection, and you need to exclude some rules using .denolint.json, there is no workaround.
If you needd the recommended rules enabled and none of them excluded, you can write an editor plugin as it is documented:
import { readFile } from 'fs/promises'
import { lint } from '@node-rs/deno-lint'
const filepath = 'lib/index.js'
const source = await readFile(filepath)
try {
const warnings = lint(filepath, source)
for (const warning of warnings) console.warn(warning)
} catch ({ message }) {
console.error(message)
}