Skip to content

chore: use Netlify linting rules #57

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
Jan 19, 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
282 changes: 20 additions & 262 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,269 +1,27 @@
module.exports = {
parser: `@babel/eslint-parser`,
extends: [
`google`,
`eslint:recommended`,
`plugin:react/recommended`,
`prettier`,
],
plugins: [`prettier`, `react`, `filenames`, `@babel`],
extends: '@netlify/eslint-config-node',
rules: {
'max-depth': 0,
complexity: 0,
'fp/no-let': 0,
'fp/no-loops': 0,
'fp/no-mutation': 0,
'fp/no-mutating-methods': 0,
'id-length': 0,
'no-magic-numbers': 0,
'no-param-reassign': 0,
'no-promise-executor-return': 0,
'no-prototype-builtins': 0,
'no-unused-vars': ['error', { ignoreRestSiblings: true }],
'unicorn/filename-case': 0,
'unicorn/numeric-separators-style': 0,
'unicorn/no-empty-file': 0,
'no-plusplus': 0,
},
parserOptions: {
ecmaVersion: 2016,
sourceType: `module`,
ecmaFeatures: {
jsx: true,
},
babelOptions: {
configFile: `./.babelrc`,
},
sourceType: 'module',
},
env: {
browser: true,
es6: true,
node: true,
jest: true,
},
globals: {
before: true,
after: true,
spyOn: true,
// These should be in scope but for some reason eslint can't see them
NodeJS: true,
JSX: true,
NodeRequire: true,
TimerHandler: true,
__PATH_PREFIX__: true,
__BASE_PATH__: true,
__ASSET_PREFIX__: true,
_CFLAGS_: true,
},
rules: {
"@babel/no-unused-expressions": [
`error`,
{
allowTaggedTemplates: true,
},
],
"no-unused-expressions": `off`,
"@babel/no-invalid-this": `error`,
"no-invalid-this": `off`,
"arrow-body-style": [
`error`,
`as-needed`,
{ requireReturnForObjectLiteral: true },
],
"new-cap": `off`,
"no-unused-vars": [
`warn`,
{
varsIgnorePattern: `^_`,
argsIgnorePattern: `^_`,
ignoreRestSiblings: 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`,
"prefer-promise-reject-errors": `warn`,
"no-prototype-builtins": `warn`,
"guard-for-in": `warn`,
"spaced-comment": [
`error`,
`always`,
{ markers: [`/`], exceptions: [`*`, `+`] },
],
camelcase: [
`error`,
{
properties: `never`,
ignoreDestructuring: true,
allow: [`^unstable_`],
},
],
},
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`],
extends: [`plugin:@typescript-eslint/recommended`],
rules: {
// We should absolutely avoid using ts-ignore, but it's not always possible.
// particular when a dependencies types are incorrect.
"@typescript-eslint/ban-ts-comment": [
`warn`,
{ "ts-ignore": `allow-with-description` },
],
// This rule is great. It helps us not throw on types for areas that are
// easily inferrable. However we have a desire to have all function inputs
// and outputs declaratively typed. So this let's us ignore the parameters
// inferrable lint.
"@typescript-eslint/no-inferrable-types": [
`error`,
{ ignoreParameters: true },
],
"@typescript-eslint/ban-types": [
`error`,
{
extendDefaults: true,
types: {
"{}": {
fixWith: `Record<string, unknown>`,
},
object: {
fixWith: `Record<string, unknown>`,
},
},
},
],
camelcase: `off`,
// TODO: These rules allow a lot of stuff and don't really enforce. If we want to apply our styleguide, we'd need to fix a lot of stuff
"@typescript-eslint/naming-convention": [
`error`,
{
selector: `default`,
format: [`camelCase`],
},
{
selector: `variable`,
format: [`camelCase`, `UPPER_CASE`, `PascalCase`],
leadingUnderscore: `allowSingleOrDouble`,
trailingUnderscore: `allowSingleOrDouble`,
},
{
selector: `function`,
format: [`camelCase`, `PascalCase`],
leadingUnderscore: `allow`,
},
{
selector: `parameter`,
format: [`camelCase`, `PascalCase`, `snake_case`],
leadingUnderscore: `allowSingleOrDouble`,
},
{
selector: `enumMember`,
format: [`camelCase`, `UPPER_CASE`, `PascalCase`],
},
{
selector: `typeLike`,
format: [`PascalCase`],
},
{
selector: `typeAlias`,
format: [`camelCase`, `PascalCase`],
},
{
selector: `property`,
format: [`PascalCase`, `UPPER_CASE`, `camelCase`, `snake_case`],
leadingUnderscore: `allowSingleOrDouble`,
},
{
selector: `objectLiteralProperty`,
format: [`PascalCase`, `UPPER_CASE`, `camelCase`, `snake_case`],
leadingUnderscore: `allowSingleOrDouble`,
trailingUnderscore: `allowSingleOrDouble`,
},
{
selector: `enum`,
format: [`PascalCase`, `UPPER_CASE`],
},
{
selector: `method`,
format: [`PascalCase`, `camelCase`],
leadingUnderscore: `allowSingleOrDouble`,
},
{
selector: `interface`,
format: [`PascalCase`],
prefix: [`I`],
},
],
// This rule tries to prevent using `require()`. However in node code,
// there are times where this makes sense. And it specifically is causing
// problems in our tests where we often want this functionality for module
// mocking. At this point it's easier to have it off and just encourage
// using top-level imports via code reviews.
"@typescript-eslint/no-var-requires": `off`,
"@typescript-eslint/no-extra-semi": `off`,
// 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`,
},
},
],
"@typescript-eslint/no-empty-function": `off`,
// 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`,
// This forces us to use interfaces over types aliases for object definitions.
// Type is still useful for opaque types
// e.g.,
// type UUID = string
"@typescript-eslint/consistent-type-definitions": [
`error`,
`interface`,
],
"@typescript-eslint/no-use-before-define": [
`error`,
{ functions: false },
],
// Allows us to write unions like `type Foo = "baz" | "bar"`
// otherwise eslint will want to switch the strings to backticks,
// which then crashes the ts compiler
quotes: `off`,
"@typescript-eslint/quotes": [
2,
`backtick`,
{
avoidEscape: true,
},
],

"@typescript-eslint/array-type": [`error`, { default: `generic` }],
},
},
],
settings: {
react: {
version: `16.9.0`,
},
},
}
File renamed without changes.
13 changes: 8 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macOS-latest] #, windows-latest] # TODO add an e2etest.bat file
node-version: [14.15.0, "*"]
node-version: [14.15.0, '*']
exclude:
- os: macOS-latest
node-version: 14.15.0
Expand All @@ -26,7 +26,10 @@ jobs:
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
check-latest: "*"
- run: npm install -g netlify-cli
- run: yarn
- run: yarn test
check-latest: '*'
- name: Install Netlify CLI
run: npm install -g netlify-cli
- name: Install dependencies
run: yarn install --ignore-engines
- name: Run tests
run: yarn test
4 changes: 2 additions & 2 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
arrowParens: `avoid`,
semi: false,
...require("@netlify/eslint-config-node/.prettierrc.json"),
endOfLine: "auto",
}
33 changes: 12 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,26 @@
}
],
"dependencies": {
"@babel/runtime": "^7.14.8",
"@babel/runtime": "^7.16.7",
"fs-extra": "^10.0.0",
"gatsby-core-utils": "^3.3.0",
"gatsby-core-utils": "^3.5.2",
"kebab-hash": "^0.1.2",
"lodash": "^4.17.21",
"webpack-assets-manifest": "^5.0.6"
},
"devDependencies": {
"@babel/cli": "^7.14.8",
"@babel/core": "^7.14.8",
"@babel/eslint-parser": "^7.14.0",
"@babel/eslint-plugin": "^7.14.0",
"@typescript-eslint/eslint-plugin": "^4.28.1",
"@typescript-eslint/parser": "^4.28.1",
"babel-preset-gatsby-package": "^2.3.0",
"@babel/cli": "^7.16.8",
"@babel/core": "^7.16.7",
"@babel/eslint-parser": "^7.16.5",
"@babel/eslint-plugin": "^7.16.5",
"@netlify/eslint-config-node": "^4.1.5",
"babel-preset-gatsby-package": "^2.5.0",
"cross-env": "^7.0.3",
"eslint": "^7.32.0",
"eslint-config-google": "^0.14.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-filenames": "^1.3.2",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-react": "^7.24.0",
"gatsby": "^4.3.0",
"gatsby-plugin-utils": "^2.3.0",
"jest": "^27.0.6",
"gatsby": "^4.5.3",
"gatsby-plugin-utils": "^2.5.0",
"jest": "^27.4.7",
"prettier": "^2.3.2",
"typescript": "^4.3.5"
"typescript": "^4.5.4"
},
"homepage": "https://github.com/netlify/gatsby-plugin-netlify#readme",
"keywords": [
Expand Down
Loading