Skip to content

Commit

Permalink
fix(dev): Correctly lint scripts typescript files (#4963)
Browse files Browse the repository at this point in the history
Previously, we've had to tell eslint to ignore TS files in package-level `scripts` directories, because they weren't included by any existing TS eslint config. This fixes that, by adding them to both our main `.eslintrc.js` and (since that new entry needs a tsconfig to which to point) our main `tsconfig.json`.
  • Loading branch information
lobsterkatie authored Apr 21, 2022
1 parent 8b6c50d commit ac7f186
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
8 changes: 8 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ module.exports = {
project: ['tsconfig.test.json'],
},
},
{
files: ['**/scripts/**/*.ts'],
parserOptions: {
// since filepaths are relative to the working directory, we need to go back up to reach the repo root level
// tsconfig
project: ['../../tsconfig.json'],
},
},
{
files: ['*.tsx'],
rules: {
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ module.exports = {
jsx: true,
},
// ignore these because they're not covered by a `tsconfig`, which makes eslint throw an error
ignorePatterns: ['scripts/prepack.ts', 'gatsby-browser.d.ts', 'gatsby-node.d.ts'],
ignorePatterns: ['gatsby-browser.d.ts', 'gatsby-node.d.ts'],
extends: ['../../.eslintrc.js'],
};
4 changes: 4 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{
"extends": "./packages/typescript/tsconfig.json",

// include scripts here because their TS config isn't package-specific, and they need to be included in a tsconfig
// file to be linted
"include": ["**/scripts/**/*.ts"],

"compilerOptions": {
// TODO: turn these on once we switch to only generating types once, using `tsconfig.types.json`
// "declaration": false,
Expand Down

0 comments on commit ac7f186

Please sign in to comment.