-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
chore(gatsby): Add TS support to eslint and improve speed #20246
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
114d322
chore(gatsby): Add TS support to eslint, improve eslint speed and fil…
blainekasten 5097ffc
Improve TS rules and fix errors
blainekasten fea4b85
Better eslint fix for unused var
blainekasten ceaa64f
Improve types for IServer
blainekasten 555739c
undo superluous change to .gitignore
blainekasten c61a004
fix lint-staged, and add rule for using interfaces
blainekasten e57c5de
Escape another build file
blainekasten e391661
Merge branch 'master' into fix/eslint-for-ts-and-speed
blainekasten f74afe2
Merge branch 'master' into fix/eslint-for-ts-and-speed
blainekasten b9bc868
Merge branch 'master' into fix/eslint-for-ts-and-speed
blainekasten cfcb853
Add typescript compiler back. Oh, where did you go?
blainekasten 3030df5
update snapshot for new babel-loader dep position
blainekasten 286b6b9
Merge branch 'master' into fix/eslint-for-ts-and-speed
blainekasten 76fa5b1
Move listeners into default export
sidharthachatterjee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
**/coverage/** | ||
**/node_modules/** | ||
bin/ | ||
packages/*/dist/** | ||
packages/*/lib/** | ||
packages/*/scripts/** | ||
**/dist/* | ||
**/__testfixtures__/** | ||
**/__tests__/fixtures/** | ||
peril | ||
docs | ||
plop-templates | ||
starters | ||
www | ||
benchmarks | ||
e2e-tests | ||
examples | ||
integration-tests | ||
**/*.d.ts | ||
|
||
packages/*/*.js | ||
packages/gatsby-plugin-preload-fonts/prepare/*.js | ||
packages/gatsby-image/withIEPolyfill/index.js | ||
packages/gatsby/cache-dir/commonjs/**/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
const TSEslint = require("@typescript-eslint/eslint-plugin") | ||
|
||
module.exports = { | ||
parser: "babel-eslint", | ||
extends: [ | ||
"google", | ||
"eslint:recommended", | ||
"plugin:flowtype/recommended", | ||
"plugin:react/recommended", | ||
"prettier", | ||
"prettier/flowtype", | ||
"prettier/react", | ||
], | ||
plugins: ["flowtype", "prettier", "react", "filenames"], | ||
parserOptions: { | ||
ecmaVersion: 2016, | ||
sourceType: "module", | ||
ecmaFeatures: { | ||
jsx: true, | ||
}, | ||
}, | ||
env: { | ||
browser: true, | ||
es6: true, | ||
node: true, | ||
jest: true, | ||
}, | ||
globals: { | ||
before: true, | ||
after: true, | ||
spyOn: true, | ||
__PATH_PREFIX__: true, | ||
__BASE_PATH__: true, | ||
__ASSET_PREFIX__: true, | ||
}, | ||
rules: { | ||
"arrow-body-style": [ | ||
"error", | ||
"as-needed", | ||
{ requireReturnForObjectLiteral: true }, | ||
], | ||
"no-unused-expressions": [ | ||
"error", | ||
{ | ||
allowTaggedTemplates: true, | ||
}, | ||
], | ||
"consistent-return": ["error"], | ||
"filenames/match-regex": ["error", "^[a-z-\\d\\.]+$", true], | ||
"no-console": "off", | ||
"no-inner-declarations": "off", | ||
"prettier/prettier": "error", | ||
quotes: ["error", "backtick"], | ||
"react/display-name": "off", | ||
"react/jsx-key": "warn", | ||
"react/no-unescaped-entities": "off", | ||
"react/prop-types": "off", | ||
"require-jsdoc": "off", | ||
"valid-jsdoc": "off", | ||
}, | ||
overrides: [ | ||
{ | ||
files: [ | ||
"packages/**/gatsby-browser.js", | ||
"packages/gatsby/cache-dir/**/*", | ||
], | ||
env: { | ||
browser: true, | ||
}, | ||
globals: { | ||
___loader: false, | ||
___emitter: false, | ||
}, | ||
}, | ||
{ | ||
files: ["**/cypress/integration/**/*", "**/cypress/support/**/*"], | ||
globals: { | ||
cy: false, | ||
Cypress: false, | ||
}, | ||
}, | ||
{ | ||
files: ["*.ts", "*.tsx"], | ||
parser: "@typescript-eslint/parser", | ||
plugins: ["@typescript-eslint/eslint-plugin"], | ||
rules: { | ||
...TSEslint.configs.recommended.rules, | ||
// This rule ensures that typescript types do not have semicolons | ||
// at the end of their lines, since our prettier setup is to have no semicolons | ||
// e.g., | ||
// interface Foo { | ||
// - baz: string; | ||
// + baz: string | ||
// } | ||
"@typescript-eslint/member-delimiter-style": [ | ||
"error", | ||
{ | ||
multiline: { | ||
delimiter: "none", | ||
}, | ||
}, | ||
], | ||
blainekasten marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// This ensures all interfaces are named with an I as a prefix | ||
// e.g., | ||
// interface IFoo {} | ||
"@typescript-eslint/interface-name-prefix": [ | ||
"error", | ||
{ prefixWithI: "always" }, | ||
], | ||
blainekasten marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"@typescript-eslint/no-empty-function": "off", | ||
blainekasten marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// This ensures that we always type the return type of functions | ||
// a high level focus of our TS setup is typing fn inputs and outputs. | ||
"@typescript-eslint/explicit-function-return-type": "error", | ||
blainekasten marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// This forces us to use interfaces over types aliases for object defintions. | ||
// Type is still useful for opaque types | ||
// e.g., | ||
// type UUID = string | ||
"@typescript-eslint/consistent-type-definitions": [ | ||
"error", | ||
"interface", | ||
], | ||
}, | ||
}, | ||
], | ||
settings: { | ||
react: { | ||
version: "16.4.2", | ||
}, | ||
}, | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,7 @@ node_modules/ | |
|
||
# misc | ||
.serverless/ | ||
.eslintcache | ||
|
||
# lock files | ||
yarn.lock | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might wanna change this line to something I use in my TS repo with backticks:
https://github.com/LekoArts/gatsby-themes/blob/master/.eslintrc.js#L47-L54
Reasoning: typescript-eslint/typescript-eslint#762
So ESLint otherwise wants to convert double quotes on types to backticks and the TS compiler doesn't like that at all!