create-ignite-app icon indicating copy to clipboard operation
create-ignite-app copied to clipboard

[Husky] Run `yarn lint` on only staged files

Open adamsoderstrom opened this issue 4 years ago • 3 comments

We currently use a tool called husky to check if the project contains any ESLint errors. The tool runs on git commit, but performs before the actual commit has occurred.

Current results

If i have an unstaged file with ESlint error, the commit will not occur.

Expected results

Husky should ignore the unstaged files and only execute yarn lint on the staged files.

adamsoderstrom avatar Dec 13 '21 11:12 adamsoderstrom

Hi @adamsoderstrom and thanks for the ticket!

Not sure how to solve this correctly. Me and @alexanderflink looked into only running the lint-staged commands on currently git staged files. This however created problems on it's own where one was now able to commit files that could cause application errors. Imagine the following scenario:

// utils.js

export function someFunction() {
  ...
}
// App.js

import { someFunction } from 'utils'

someFunction()

The code above is currently commited to git. Now you decide to refactor the util called someFunction and while you're at it you also rename it to someOtherFunction because the functionality has changed. This would then leave you with the code below:

// utils.js

export function someOtherFunction() {
  ...
}
// App.js

import { someFunction } from 'utils'

someFunction()

Now you do a git status and the only modified file is the utils file that you just refactored so you decide to commit it. Our setup would then only run the lint-staged commands on currently staged files which would then validate as there are no errors in utils.js and the commit would go through. However, this is an issue because we are still importing the old someFunction in App.js and this file was not linted upon committing since that files was not staged.

maeertin avatar Dec 16 '21 21:12 maeertin

Maybe the solution to this is to fix lint-staged like we tried before so that only your staged files are linted, but to also have a hook so that everything is linted when you try to push your changes. That way you can have linting errors locally in unstaged files, but to be able to push, everything must be linted correctly.

alexanderflink avatar Dec 17 '21 09:12 alexanderflink

Actually that sounds like a super neat solution, let's look into this! @alexanderflink

maeertin avatar Oct 26 '22 20:10 maeertin

Closing PR as no longer relevant as "cia" is now purely a documentation app.

maeertin avatar Aug 23 '24 12:08 maeertin