Lint-staged: No staged files match src/**/*.{ts,tsx}

Created on 27 Oct 2017  ·  10Comments  ·  Source: okonet/lint-staged

Why I get this error while run precommit script?

MBP-Pavel:components pavel$ nvm version
v8.5.0
MBP-Pavel:components pavel$ node -v
v8.5.0
MBP-Pavel:components pavel$ npm -v
5.5.1
MBP-Pavel:components pavel$ npm run precommit

> [email protected] precommit /Users/pavel/Work/astralnalog/components
> lint-staged

 ↓ Running tasks for src/**/*.{ts,tsx} [skipped]
   → No staged files match src/**/*.{ts,tsx}

package.json

"devDependencies": {
  ...
  "husky": "^0.15.0-beta.11",
  "lint-staged": "^4.3.0",
  "prettier": "^1.7.4",
  "tslint": "^5.8.0",
  "typescript": "^2.5.3",
},
"husky": {
  "hooks": {
    "pre-commit": "lint-staged"
  }
}

.lintstagedrc

{
  "src/**/*.{ts,tsx}": ["prettier --write", "git add"]
}

2017-10-27 9 24 58

Most helpful comment

having a single type, i.e. *.{js} can also break it, use *.js

All 10 comments

Hey @perevezencev, what is the error you are referring to? lint-staged is telling you that there are no staged files to lint. You need to stage files(ex: git add .) in order for lint-staged to run your commands.

I am seeing this issue - but I have added files, and they are staged.

@perevezencev How did you solve it? I'm also facing the same issue. Files are staged, but lint-staged says there's nothing to do.

@jackson-sandland, @perevezencev I'd be happy to help you if I can. Please enable and log the debug output and share it here or in a new issue.

@jackson-sandland Facing the same problem, with staged files

$: git status

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        modified:   src/scenes/Counseling/context/CouncelingSessionContext.tsx

.lintstagedrc

{
  "lint-staged": {
    "*.{ts, tsx}": ["tslint --fix --config tslint.json --project tsconfig.json", "git add"]
  }
}

package.json

{
  ...
  "dependencies": {
    "react": "^16.4.1",
    "react-dom": "^16.4.1",
    "react-router-dom": "^4.3.1",
  },
  "scripts": {
    ...
  },
  "devDependencies": {
    "@types/react": "^16.4.1",
    "@types/react-dom": "^16.0.6",
    "@types/react-router-dom": "^4.2.7",
    "husky": "^0.14.3",
    "lint-staged": "^7.2.0",
    "prettier": "^1.13.7",
    "tslint-plugin-prettier": "^1.3.0",
    "typescript": "^2.9.2"
  }
}

tsconfig.json

{
  "compilerOptions": {
    "baseUrl": ".",
    "outDir": "build/dist",
    "module": "esnext",
    "target": "es5",
    "lib": ["es6", "dom"],
    "sourceMap": true,
    "allowJs": false,
    "allowSyntheticDefaultImports": true,
    "jsx": "react",
    "moduleResolution": "node",
    "rootDirs": ["src"],
    "forceConsistentCasingInFileNames": true,
    "noImplicitReturns": true,
    "noImplicitThis": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "suppressImplicitAnyIndexErrors": true,
    "noUnusedLocals": true,
    "keyofStringsOnly": true,
    "declaration": false,
    "paths": {
      "src/*": ["src/*"]
    }
  },
  "exclude": [
    "node_modules",
    "build",
    "scripts",
    "acceptance-tests",
    "webpack",
    "jest",
    "src/setupTests.ts"
  ]
}

tslint.json

{
  "rulesDirectory": ["tslint-plugin-prettier"],
  "extends": ["tslint:recommended", "tslint-react", "tslint-config-prettier"],
  "linterOptions": {
    "exclude": ["config/**/*.js", "node_modules/**/*.ts"]
  },
  "defaultSeverity": "warning",
  "rules": {
    // override tslint-react rules here
    "prettier": true
  }
}

.prettierrc.json

{
  "singleQuote": true,
  "tabWidth": 2,
  "semi": false,
  "jsxBracketSameLine": true,
  "trailingComma": "es5"
}
$: yarn lint-staged
 ↓ Running tasks for lint-staged [skipped]
   → No staged files match lint-staged
✨  Done in 0.63s.

I noticed that → No staged files match lint-staged was referring to the key in .lintstagedrc and changed it to

{
  "*.{ts, tsx}": ["tslint --fix --config tslint.precommit.json --project tsconfig.json", "git add"]
}

But did not help, now i get

$: yarn lint-staged
 ↓ Running tasks for lint-staged [skipped]
   → No staged files match *.{ts, tsx}
✨  Done in 0.63s.

I solved my problem, I had a space in between ts, and tsx
change in .lintstagedrc.json from "*.{ts, tsx}" to "*.{ts,tsx}"

$: yarn lint-staged
 ✔ Running tasks for *.{ts,tsx}
✨  Done in 4.99s.

having a single type, i.e. *.{js} can also break it, use *.js

真让人头疼.

  "lint-staged": {
    "**/*.ts?(x)": [
      "eslint -c .eslintrc.js --fix",
      "git add"
    ]
  },



导入eslintrc配置可解决问题

I solved my problem, I had a space in between ts, and tsx
change in .lintstagedrc.json from "*.{ts, tsx}" to "*.{ts,tsx}"

$: yarn lint-staged
 ✔ Running tasks for *.{ts,tsx}
✨  Done in 4.99s.

thanks my friend its solved my problem too...

Was this page helpful?
0 / 5 - 0 ratings

Related issues

yoannmoinet picture yoannmoinet  ·  8Comments

OriginUnknown picture OriginUnknown  ·  4Comments

jasonslyvia picture jasonslyvia  ·  3Comments

jitenderchand1 picture jitenderchand1  ·  3Comments

jakearchibald picture jakearchibald  ·  8Comments