ls-lint icon indicating copy to clipboard operation
ls-lint copied to clipboard

FR: lint individual files

Open chrisgrieser opened this issue 1 year ago • 1 comments

Right now, ls-lint only allows us to lint all files/folders in the current directory, or a directory specified via --workdir. I'd like to propose the ability to also lint an individual filename (or technically: a string containing a filename)

Example

ls-lint --single-file "src/foo-bar.js"
# or maybe
echo "myFileName.js" | ls-lint --single-file --stdin

Rationale

Linting individual files would make ls-lint more flexible to use. For instance, this would allow us to integrate it into an IDE and provide live information when a file was renamed into an undesired form. Another possible use case would be to directly validate user input for file creation or file renaming operations in a script.

chrisgrieser avatar Nov 19 '23 22:11 chrisgrieser

This will also allow ls-lint to be used as a pre-commit hook.

romanstetsyk avatar Dec 04 '23 20:12 romanstetsyk

This feature is now available in the v2.3.0-beta.1 release. Please test it and let me know if there are any issues ❤️

The upcoming v2.3.0 blog post: https://ls-lint.org/blog/announcements/v2.3.0.html The docs: https://ls-lint.org/2.3/getting-started/introduction.html The release notes: https://github.com/loeffel-io/ls-lint/releases/tag/v2.3.0-beta.1

loeffel-io avatar Jul 16 '24 10:07 loeffel-io

I upgrade to v2.3.0-beta.1, but still lint full project.

It looks like lint full project but only error output passed files. Expected only lint passed files.

I run command:

pnpm exec ls-lint --debug ABCD.ts

My .ls-lint.yml:

ls:
  .*: kebab-case

ignore:
  - ./.git
  - ./.husky
  - ./.vscode
  - "**/.turbo"
  - "**/dist"
  - "**/node_modules"
  - "**/README.md"

Output:

-----------------------------
statistics
-----------------------------
time: 37.049546s
paths: 5485
file skips: 17
dirs: 548
dir skips: 30
=============================
ABCD.ts failed for `.*` rules: kebabcase

fkworld avatar Jul 31 '24 02:07 fkworld

Thank you @fkworld for your contribution!

So the error looks right, right?

ls-lint still lints the full workdir but errors only for the passed files - this is because the new exists rule makes it very hard to pass only the passed files to the filesystem that are needed for exists. exists works on directories which makes it impossible to only pass ABAC.ts to the filesystem.

There is definitely room for optimizations and i try to target them in future releases.

I never saw ls-lint running for 37s btw - can you please provide the ls-lint time running with ls-lint v2.2.3 🙏

Thank you!

loeffel-io avatar Jul 31 '24 08:07 loeffel-io

@loeffel-io I understand.

About running for 37s, I fixed that, now less than 1s. I was started another issue #246 to provide more information.

fkworld avatar Aug 01 '24 09:08 fkworld