Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running TSLint only on changed files with Git Diff

Tags:

git

tslint

I want to run tslint only on files that were modified in a pull request, instead of the entire project.

git diff --name-only develop -- *.ts successfully prints out the filenames that have changed between the feature branch and develop.

I'm trying to pipe that command into my lint command. Lint can take in a list of files to run against instead of running against everything by placing the filenames after:

git diff --name-only develop -- *.ts | npm run lint

This works on our Jenkins box, but on my local Windows machine no text gets appended to the end of the lint command.

C:\code>git diff --name-only develop-- *.ts | npm run lint

tslint -c .\tslint.json -p .\tsconfig.json

Is there a simple one line method that will only run lint on changed files in a branch?

like image 706
mlapaglia Avatar asked Sep 20 '25 11:09

mlapaglia


1 Answers

I got a list of modified files by running

git diff --name-only --diff-filter=ACMR origin/dev-123...develop -- *.ts

Where origin/dev-123 is the source branch and develop is the destination.

I put the output of that command into an array, and ran the linter against the array of files.

like image 88
mlapaglia Avatar answered Sep 22 '25 14:09

mlapaglia