I have husky and lint-staged set up in my package.json file and it runs, but on all files, whereas I would expect it to run on only staged files.
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"./**/*.js": [
"eslint . --fix --quiet"
]
},
{
"name": "HomeSlice",
"version": "1.0.0",
"main": "src/index.js",
"license": "MIT",
"scripts": {
"lint": "eslint './**/*.js' --quiet",
"lint:fix": "eslint './**/*.js' --fix --quiet",
"format": "prettier --write '**/*.js'",
"start": "pm2 start",
"poststart": "pm2 logs",
"mongo:start": "docker-compose up -d mongo mongo-express",
"mongo:stop": "docker-compose down",
"mongo:destroy": "docker-compose down -v && rm -rf ./data/db",
"dev": "NODE_ENV=development pm2 start",
"dev:quiet": "NODE_ENV=development QUIET_LOGS=yes pm2 start",
"dev:server": "NODE_ENV=development pm2 start --only 'homeslice'",
"dev:server:log": "pm2 logs homeslice",
"dev:server:log:extra": "pm2 logs homeslice --lines 100",
"dev:worker": "NODE_ENV=development pm2 start --only 'toucan-workers'",
"dev:worker:log": "pm2 logs toucan-workers",
"dev:stop": "pm2 kill",
"test": "NODE_ENV=test jest --runInBand",
"test:unit": "UNIT=1 jest --runInBand",
"test:watch": "jest --watch",
"fixture:load": "NODE_ENV=development node -r esm bin/fixture load",
"fixture:unload": "NODE_ENV=development node -r esm bin/fixture unload",
"preinstall": "node -e \"if (process.env.npm_execpath.indexOf('yarn') === -1) throw new Error('Use yarn for installing: https://yarnpkg.com/en/docs/install')\""
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"./**/*.js": [
"eslint . --fix --quiet"
]
},
"dependencies": {
"@babel/node": "^7.8.7",
"@babel/runtime": "^7.9.2",
"@sentry/node": "5.6.2",
"agenda": "^2.2.0",
"analytics-node": "^3.4.0-beta.1",
"apollo-server-express": "^2.6.1",
"aws-sdk": "^2.541.0",
"base62-random": "^0.3.5",
"bcryptjs": "^2.4.3",
"commander": "^4.0.1",
"cors": "^2.8.5",
"csv-parser": "^2.3.2",
"esm": "^3.2.25",
"express": "^4.17.1",
"express-jwt": "^5.3.1",
"express-session": "^1.16.1",
"graphql": "^14.3.1",
"graphql-extensions": "^0.10.4",
"graphql-middleware": "^4.0.2",
"graphql-shield": "^7.0.4",
"graphql-tools": "^5.0.0",
"joi": "^14.3.1",
"jsonwebtoken": "^8.5.1",
"lodash": "^4.17.15",
"mandrill-api": "^1.0.45",
"mime": "^2.4.4",
"moment": "^2.24.0",
"mongoose": "^5.5.12",
"mongoose-findorcreate": "^3.0.0",
"node-mongodb-fixtures": "^3.1.2",
"nodemon": "^1.19.1",
"pm2": "^4.2.1",
"redis": "^2.8.0",
"redis-clustr": "^1.7.0",
"stripe": "^7.2.0",
"uuid4": "^1.1.4",
"validator": "^12.2.0",
"verror": "^1.10.0",
"winston": "^3.2.1",
"winston-loggly-bulk": "3.0.1",
"x-ray": "^2.3.4",
"x-ray-phantom": "^1.0.1"
},
"devDependencies": {
"@babel/cli": "^7.8.4",
"@babel/core": "^7.9.6",
"@babel/preset-env": "^7.9.6",
"@types/jest": "^24.0.19",
"babel-jest": "^24.9.0",
"babel-plugin-module-resolver": "^4.0.0",
"eslint": "^6.8.0",
"eslint-config-airbnb-base": "^14.1.0",
"eslint-config-prettier": "^6.11.0",
"eslint-import-resolver-babel-module": "^5.1.2",
"eslint-plugin-import": "^2.20.2",
"eslint-plugin-module-resolver": "^0.16.0",
"eslint-plugin-prefer-arrow": "^1.2.1",
"eslint-plugin-prettier": "^3.1.3",
"husky": "^4.2.5",
"jest": "^24.9.0",
"lint-staged": "^10.2.4",
"prettier": "2.0.5",
"supervisor": "^0.12.0"
}
}
husky > pre-commit (node v12.14.1)
2020-05-18T23:23:20.764Z lint-staged:bin Running `[email protected]`
2020-05-18T23:23:20.765Z lint-staged:bin Options parsed from command-line: {
allowEmpty: false,
concurrent: true,
configPath: undefined,
debug: true,
maxArgLength: 131072,
stash: true,
quiet: false,
relative: false,
shell: false,
verbose: false
}
2020-05-18T23:23:20.766Z lint-staged Loading config using `cosmiconfig`
2020-05-18T23:23:20.779Z lint-staged Successfully loaded config from `/Users/rjohnson/Documents/dev/penguin/homeslice/package.json`:
{ './**/*.js': [ 'eslint . --fix --quiet' ] }
2020-05-18T23:23:20.779Z lint-staged:cfg Validating config
Running lint-staged with the following config:
{
'./**/*.js': [
'eslint . --fix --quiet'
]
}
2020-05-18T23:23:20.780Z lint-staged Unset GIT_LITERAL_PATHSPECS (was `undefined`)
2020-05-18T23:23:20.780Z lint-staged:run Running all linter scripts
2020-05-18T23:23:20.780Z lint-staged:resolveGitRepo Resolving git repo from `/Users/rjohnson/Documents/dev/penguin/homeslice`
2020-05-18T23:23:20.780Z lint-staged:resolveGitRepo Unset GIT_DIR (was `undefined`)
2020-05-18T23:23:20.780Z lint-staged:git Running git command [ 'rev-parse', '--show-toplevel' ]
2020-05-18T23:23:20.790Z lint-staged:resolveGitRepo Resolved git directory to be `/Users/rjohnson/Documents/dev/penguin/homeslice`
2020-05-18T23:23:20.790Z lint-staged:resolveGitRepo Resolved git config directory to be `/Users/rjohnson/Documents/dev/penguin/homeslice/.git`
2020-05-18T23:23:20.790Z lint-staged:git Running git command [ 'log', '-1' ]
2020-05-18T23:23:20.798Z lint-staged:git Running git command [ 'diff', '--staged', '--diff-filter=ACMR', '--name-only', '-z' ]
2020-05-18T23:23:20.806Z lint-staged:run Loaded list of staged files in git:
[
'package.json',
'src/models/pack.js',
'src/resolvers/learning.js',
'src/resolvers/pack.js',
'src/services/learning/learning.js',
'src/services/pack/packs.js',
'src/typeDefs/learning.js',
'src/typeDefs/pack.js',
'yarn.lock'
]
2020-05-18T23:23:20.806Z lint-staged:chunkFiles Resolved an argument string length of 655 characters from 9 files
2020-05-18T23:23:20.806Z lint-staged:chunkFiles Creating 1 chunks for maxArgLength of 131072
2020-05-18T23:23:20.807Z lint-staged:gen-tasks Generating linter tasks
2020-05-18T23:23:20.808Z lint-staged:gen-tasks Generated task:
{
pattern: './**/*.js',
commands: [ 'eslint . --fix --quiet' ],
fileList: [
'/Users/rjohnson/Documents/dev/penguin/homeslice/src/models/pack.js',
'/Users/rjohnson/Documents/dev/penguin/homeslice/src/resolvers/learning.js',
'/Users/rjohnson/Documents/dev/penguin/homeslice/src/resolvers/pack.js',
'/Users/rjohnson/Documents/dev/penguin/homeslice/src/services/learning/learning.js',
'/Users/rjohnson/Documents/dev/penguin/homeslice/src/services/pack/packs.js',
'/Users/rjohnson/Documents/dev/penguin/homeslice/src/typeDefs/learning.js',
'/Users/rjohnson/Documents/dev/penguin/homeslice/src/typeDefs/pack.js'
]
}
2020-05-18T23:23:20.809Z lint-staged:make-cmd-tasks Creating listr tasks for commands [ 'eslint . --fix --quiet' ]
2020-05-18T23:23:20.809Z lint-staged:task cmd: eslint
2020-05-18T23:23:20.809Z lint-staged:task args: [ '.', '--fix', '--quiet' ]
2020-05-18T23:23:20.809Z lint-staged:task execaOptions: { preferLocal: true, reject: false, shell: false }
2020-05-18T23:23:20.809Z lint-staged:chunkFiles Resolved an argument string length of 530 characters from 7 files
2020-05-18T23:23:20.809Z lint-staged:chunkFiles Creating 1 chunks for maxArgLength of 131072
[STARTED] Preparing...
2020-05-18T23:23:20.812Z lint-staged:git Backing up original state...
2020-05-18T23:23:20.812Z lint-staged:git Getting partially staged files...
2020-05-18T23:23:20.812Z lint-staged:git Running git command [ 'status', '--porcelain' ]
2020-05-18T23:23:20.823Z lint-staged:git Found partially staged files: []
2020-05-18T23:23:20.823Z lint-staged:git Backing up merge state...
2020-05-18T23:23:20.823Z lint-staged:file Reading file `/Users/rjohnson/Documents/dev/penguin/homeslice/.git/MERGE_HEAD`
2020-05-18T23:23:20.824Z lint-staged:file Reading file `/Users/rjohnson/Documents/dev/penguin/homeslice/.git/MERGE_MODE`
2020-05-18T23:23:20.824Z lint-staged:file Reading file `/Users/rjohnson/Documents/dev/penguin/homeslice/.git/MERGE_MSG`
2020-05-18T23:23:20.824Z lint-staged:file File `/Users/rjohnson/Documents/dev/penguin/homeslice/.git/MERGE_HEAD` doesn't exist, ignoring...
2020-05-18T23:23:20.824Z lint-staged:file File `/Users/rjohnson/Documents/dev/penguin/homeslice/.git/MERGE_MODE` doesn't exist, ignoring...
2020-05-18T23:23:20.824Z lint-staged:file File `/Users/rjohnson/Documents/dev/penguin/homeslice/.git/MERGE_MSG` doesn't exist, ignoring...
2020-05-18T23:23:20.824Z lint-staged:git Done backing up merge state!
2020-05-18T23:23:20.824Z lint-staged:git Getting deleted files...
2020-05-18T23:23:20.824Z lint-staged:git Running git command [ 'ls-files', '--deleted' ]
2020-05-18T23:23:20.831Z lint-staged:git Found deleted files: []
2020-05-18T23:23:20.831Z lint-staged:git Running git command [ 'stash', 'create' ]
2020-05-18T23:23:21.000Z lint-staged:git Running git command [
'stash',
'store',
'--quiet',
'--message',
'lint-staged automatic backup',
'd464c70303890d850ddd1300d08fd65e4df89bd5'
]
2020-05-18T23:23:21.068Z lint-staged:git Done backing up original state!
[SUCCESS] Preparing...
[STARTED] Running tasks...
[STARTED] Running tasks for ./**/*.js
[STARTED] eslint . --fix --quiet
[FAILED] eslint . --fix --quiet [FAILED]
[FAILED] eslint . --fix --quiet [FAILED]
[SUCCESS] Running tasks...
[STARTED] Applying modifications...
[STARTED] Reverting to original state because of errors...
2020-05-18T23:23:27.871Z lint-staged:git Restoring original state...
2020-05-18T23:23:27.871Z lint-staged:git Running git command [ 'reset', '--hard', 'HEAD' ]
2020-05-18T23:23:27.905Z lint-staged:git Running git command [ 'stash', 'list' ]
2020-05-18T23:23:27.999Z lint-staged:git Running git command [ 'stash', 'apply', '--quiet', '--index', 'stash@{0}' ]
2020-05-18T23:23:28.321Z lint-staged:git Restoring merge state...
2020-05-18T23:23:28.321Z lint-staged:git Done restoring merge state!
2020-05-18T23:23:28.322Z lint-staged:file Removing file `/Users/rjohnson/Documents/dev/penguin/homeslice/.git/lint-staged_unstaged.patch`
2020-05-18T23:23:28.322Z lint-staged:file File `/Users/rjohnson/Documents/dev/penguin/homeslice/.git/lint-staged_unstaged.patch` doesn't exist, ignoring...
2020-05-18T23:23:28.322Z lint-staged:git Done restoring original state!
[SUCCESS] Reverting to original state because of errors...
[STARTED] Cleaning up...
2020-05-18T23:23:28.323Z lint-staged:git Dropping backup stash...
2020-05-18T23:23:28.323Z lint-staged:git Running git command [ 'stash', 'list' ]
2020-05-18T23:23:28.503Z lint-staged:git Running git command [ 'stash', 'drop', '--quiet', 'stash@{0}' ]
2020-05-18T23:23:28.735Z lint-staged:git Done dropping backup stash!
[SUCCESS] Cleaning up...
✖ eslint . --fix --quiet:
/Users/rjohnson/Documents/dev/penguin/homeslice/migrations/sample-migration.js
1:21 error 'db' is defined but never used no-unused-vars
1:25 error 'client' is defined but never used no-unused-vars
8:23 error 'db' is defined but never used no-unused-vars
8:27 error 'client' is defined but never used no-unused-vars
✖ 4 problems (4 errors, 0 warnings)
lint-staged: 10.2.4Hello, basically _lint-staged_ will append the staged file paths at the end of your command. Your command already includes . which will recursively match all files for eslint. Removing the dot should fix it for you.
@iiroj Thank you so much!
Most helpful comment
Hello, basically _lint-staged_ will append the staged file paths at the end of your command. Your command already includes
.which will recursively match all files for eslint. Removing the dot should fix it for you.