Skip to content

fix(dev): Fix linting for top-level scripts folder #4977

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,9 @@ module.exports = {
},
},
{
files: ['**/scripts/**/*.ts'],
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'],
project: ['tsconfig.dev.json'],
},
},
{
Expand Down
8 changes: 8 additions & 0 deletions packages/gatsby/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,13 @@ module.exports = {
},
// ignore these because they're not covered by a `tsconfig`, which makes eslint throw an error
ignorePatterns: ['gatsby-browser.d.ts', 'gatsby-node.d.ts'],
overrides: [
{
files: ['scripts/**/*.ts'],
parserOptions: {
project: ['../../tsconfig.dev.json'],
},
},
],
extends: ['../../.eslintrc.js'],
};
5 changes: 4 additions & 1 deletion scripts/build-types-watch.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-console */
/**
* If `yarn build:types:watch` is run without types files previously having been created, the build will get stuck in an
* errored state. This happens because lerna runs all of the packages' `yarn build:types:watch` statements in parallel,
Expand Down Expand Up @@ -28,7 +29,9 @@ for (const pkg of packages) {
continue;
}

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

if ('build:types' in packageJSON.scripts && !fs.existsSync(path.resolve(packagePath, 'build/types'))) {
console.warn(
Expand Down
6 changes: 6 additions & 0 deletions tsconfig.dev.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// TODO This should eventually end up as the tsconfig for a dev-utils package
{
"extends": "./tsconfig.json",

"include": ["**/scripts/**/*.ts"],
}
4 changes: 0 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
{
"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