Skip to content

Commit ef06081

Browse files
lobsterkatieAbhiPrasad
authored andcommitted
fix(dev): Fix linting for top-level scripts folder (#4977)
This is a follow up to #4963, which aimed to fix linting for `ts-node` scripts. That PR worked for `packages/*/scripts/*.ts`, but turned out not to work for the top-level `scripts/*.ts`, because the glob for file matching in the eslint config override matched both sets of scripts, but the tsconfig being pointed at only worked for package-level scripts. This fixes that by pulling the package-level linting override into the package-level `.eslintrc.js`, thus allowing the top-level override to apply only to the top-level scripts folder. Also, in order not to have to muck with the main repo `tsconfig` in any future changes/fixes, both sets of scripts now point to a new, dev-specific tsconfig for their linting. Finally, it fixes linting errors in the top-level `build:types:watch` script which were brought to light by the newly-fixed linting.
1 parent 22156f6 commit ef06081

File tree

5 files changed

+20
-9
lines changed

5 files changed

+20
-9
lines changed

.eslintrc.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,9 @@ module.exports = {
3434
},
3535
},
3636
{
37-
files: ['**/scripts/**/*.ts'],
37+
files: ['scripts/**/*.ts'],
3838
parserOptions: {
39-
// since filepaths are relative to the working directory, we need to go back up to reach the repo root level
40-
// tsconfig
41-
project: ['../../tsconfig.json'],
39+
project: ['tsconfig.dev.json'],
4240
},
4341
},
4442
{

packages/gatsby/.eslintrc.js

+8
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,13 @@ module.exports = {
88
},
99
// ignore these because they're not covered by a `tsconfig`, which makes eslint throw an error
1010
ignorePatterns: ['gatsby-browser.d.ts', 'gatsby-node.d.ts'],
11+
overrides: [
12+
{
13+
files: ['scripts/**/*.ts'],
14+
parserOptions: {
15+
project: ['../../tsconfig.dev.json'],
16+
},
17+
},
18+
],
1119
extends: ['../../.eslintrc.js'],
1220
};

scripts/build-types-watch.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable no-console */
12
/**
23
* If `yarn build:types:watch` is run without types files previously having been created, the build will get stuck in an
34
* errored state. This happens because lerna runs all of the packages' `yarn build:types:watch` statements in parallel,
@@ -28,7 +29,9 @@ for (const pkg of packages) {
2829
continue;
2930
}
3031

31-
const packageJSON = JSON.parse(fs.readFileSync(path.resolve(packagePath, 'package.json'), 'utf-8'));
32+
const packageJSON = JSON.parse(fs.readFileSync(path.resolve(packagePath, 'package.json'), 'utf-8')) as {
33+
scripts: Record<string, string>;
34+
};
3235

3336
if ('build:types' in packageJSON.scripts && !fs.existsSync(path.resolve(packagePath, 'build/types'))) {
3437
console.warn(

tsconfig.dev.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// TODO This should eventually end up as the tsconfig for a dev-utils package
2+
{
3+
"extends": "./tsconfig.json",
4+
5+
"include": ["**/scripts/**/*.ts"],
6+
}

tsconfig.json

-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
{
22
"extends": "./packages/typescript/tsconfig.json",
33

4-
// include scripts here because their TS config isn't package-specific, and they need to be included in a tsconfig
5-
// file to be linted
6-
"include": ["**/scripts/**/*.ts"],
7-
84
"compilerOptions": {
95
// TODO: turn these on once we switch to only generating types once, using `tsconfig.types.json`
106
// "declaration": false,

0 commit comments

Comments
 (0)