keyshade icon indicating copy to clipboard operation
keyshade copied to clipboard

chore: Lint and format only staged changes

Open AlexVascon opened this issue 9 months ago • 16 comments

User description

Description

This commit adds the package lint-staged. This package makes sure only staged changes are scanned for linting and formating instead of every file. I think when lint-staged is calling pnpm run lint it passes some file arguments. Since pnpm run lint calls turbo run lint this argument is getting passed directly resulting in an error as extra arguments get added to the tubro command. to prevent this we add '--' to signigy not to pass on further arguments.

I based this from a comment made by github user mehulkar whos explanation and solution helped me solve this problem. link here

Give a summary of the change that you have made

Changes are made to 2 files.

package.json root .husky/pre-commit

In the package.json a section is included for lint-staged. Within 2 commands are set so only lint and formating are run on staged commits and not the whole file. These commands where moved from the husky pre-commit file and replaced with pnpm run lint-staged. This calls the code under lint-staged in the package.json.

Fixes #195 [] issue 195 link here

This commit fixes the issue where all files got scanned for linting and formating which is very slow and it's better that only the staged files get scanned as they contain changes.

Dependencies

lint-staged

Mention any dependencies/packages used

lint-staged

Future Improvements

Mention any improvements to be done in future related to any file/feature

Mentions

Mention and tag the people

Screenshots of relevant screens

Screenshot 2024-05-07 at 16 21 09 Screenshot 2024-05-07 at 16 22 12

This screenshot below is what it looks like if you dont use lint-staged. I edited the pre-commit file and changed pnpm lint-staged to pnpm lint.

Screenshot 2024-05-07 at 16 58 52

Add screenshots of relevant screens

Developer's checklist

  • [ ] My PR follows the style guidelines of this project
  • [ ] I have performed a self-check on my work

If changes are made in the code:

  • [ x] I have followed the coding guidelines
  • [x ] My changes in code generate no new warnings
  • [ ] My changes are breaking another fix/feature of the project
  • [ ] I have added test cases to show that my feature works
  • [ ] I have added relevant screenshots in my PR
  • [ x] There are no UI/UX issues

Documentation Update

  • [ ] This PR requires an update to the documentation at docs.keyshade.xyz
  • [x ] I have made the necessary updates to the documentation, or no documentation changes are required.

Type

enhancement, bug_fix


Description

  • Integrated lint-staged in package.json to ensure only staged files are linted and formatted, improving performance.
  • Updated the Husky pre-commit hook to use lint-staged, streamlining the pre-commit checks.
  • Added lint-staged to devDependencies to manage the new dependency.

Changes walkthrough

Relevant files
Enhancement
package.json
Integrate lint-staged for Efficient Linting and Formatting

package.json

  • Added a new lint-staged configuration to handle linting and formatting
    of staged files.
  • Updated devDependencies to include lint-staged version ^15.2.2.
  • +10/-0   
    Configuration changes
    pre-commit
    Update Husky Pre-commit Hook to Use lint-staged                   

    .husky/pre-commit

  • Replaced direct lint and format commands with npx lint-staged to
    utilize the new lint-staged configuration.
  • Retained existing pnpm test:api command.
  • +1/-1     

    PR-Agent usage: Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    AlexVascon avatar May 01 '24 11:05 AlexVascon