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

deno-lint: cli ignores path #631

Open
zachauten opened this issue Apr 20, 2022 · 3 comments
Open

deno-lint: cli ignores path #631

zachauten opened this issue Apr 20, 2022 · 3 comments

Comments

@zachauten
Copy link

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. 
@prantlf
Copy link
Contributor

prantlf commented Aug 1, 2022

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.

@hadriann
Copy link

@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.

@prantlf
Copy link
Contributor

prantlf commented Sep 24, 2022

@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)
}

prantlf added a commit to prantlf/denolint that referenced this issue Sep 28, 2022
This is the first version released after forking the [customisation] of the [original project].

* Scan specific directories ([631], [647])
* Scan directories configured by `files.include` ([635], [645])
* Fix handling of the configuration `files.exclude` ([635], [646])
* Support disabling rules in souces using `eslint-disable` ([630], [642])
* Support including and excluding rules in the `lint` method ([631], [643])
* Execute the command-line tool `denolint` without loading the Node.js VM ([648])
* Allow specifying directories, files and patterns as input for checking

[customisation]: https://github.com/prantlf/node-rs/commits/combined
[original project]: https://github.com/napi-rs/node-rs/tree/main/packages/deno-lint
[630]: napi-rs/node-rs#630
[631]: napi-rs/node-rs#631
[635]: napi-rs/node-rs#635
[642]: napi-rs/node-rs#642
[643]: napi-rs/node-rs#643
[645]: napi-rs/node-rs#645
[646]: napi-rs/node-rs#646
[647]: napi-rs/node-rs#647
[648]: napi-rs/node-rs#648
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants