Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VernonGrant/ebe9eb963436c770ab90637ff69f08d4 to your computer and use it in GitHub Desktop.
Save VernonGrant/ebe9eb963436c770ab90637ff69f08d4 to your computer and use it in GitHub Desktop.
How to lint only changed files?

find out the differences

use git diff to generate file list

git diff --name-only master

limited to certain file types

add ext filter

git diff --name-only master | grep -E "(.js$|.ts$|.tsx$)"

handle the case of file removal

ignore deleted files

git diff --name-only --diff-filter=ACMRTUXB master | grep -E "(.js$|.ts$|.tsx$)"

node scripts

add eslint to package.json

....
"scripts":
  "lint:script": "eslint -c eslintrc.js $(git diff --name-only --diff-filter=ACMRTUXB master | grep  -E \"(.js$|.ts$|.tsx$)\")"

CI script

sample with circle ci here

....
"scripts":
 "lint:script": "eslint -c eslintrc.js $(git diff --name-only --diff-filter=ACMRTUXB origin/master | grep  -E \"(.js$|.ts$|.tsx$)\")"

for stylelint

will need grep fallback for empty result cases

 
 ....
 "scripts":
   "lint:style": "stylelint --config .stylelintrc.js $(git diff --name-only --diff-filter=ACMRTUXB origin/master | grep  -E \"(.js$|.ts$|.tsx$)\" || echo \".stylelintrc.js\")"

NOTE: make sure our local branch is up to date (merge origin/master)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment