Skip to content
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: Fix our internal eslint config for monorepo #29795

Merged
merged 2 commits into from
Feb 26, 2021
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
57 changes: 49 additions & 8 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,10 @@ module.exports = {
...TSEslint.configs.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": {
"ts-ignore": "allow-with-description",
},
"@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
Expand All @@ -125,22 +126,62 @@ module.exports = {
},
},
],
"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"] },
{
selector: "parameter",
format: ["camelCase"],
selector: "variable",
format: ["camelCase", "UPPER_CASE", "PascalCase"],
leadingUnderscore: "allowSingleOrDouble",
trailingUnderscore: "allowSingleOrDouble",
},
{
selector: "function",
format: ["camelCase", "PascalCase"],
leadingUnderscore: "allow",
prefix: ["unstable_", ""],
},
{
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"],
Expand All @@ -153,14 +194,14 @@ module.exports = {
// 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/no-extra-semi": false,
"@typescript-eslint/member-delimiter-style": [
"error",
{
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-link/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from "react"
import { NavigateFn, LinkProps } from "@reach/router"

// eslint-disable-next-line @typescript-eslint/interface-name-prefix
// eslint-disable-next-line @typescript-eslint/naming-convention
export interface GatsbyLinkProps<TState> extends LinkProps<TState> {
/** A class to apply when this Link is active */
activeClassName?: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as hooks from "../hooks"

type GlobalOverride = NodeJS.Global &
typeof global.globalThis & {
// eslint-disable-next-line @typescript-eslint/naming-convention
GATSBY___IMAGE: boolean
SERVER: boolean
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { SourceProps } from "../picture"
type GlobalOverride = NodeJS.Global &
typeof global.globalThis & {
SERVER: boolean | undefined
// eslint-disable-next-line @typescript-eslint/naming-convention
GATSBY___IMAGE: boolean | undefined
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { MainImageProps } from "./main-image"
import { Layout } from "../image-utils"
import { getSizer } from "./layout-wrapper"

// eslint-disable-next-line @typescript-eslint/interface-name-prefix
// eslint-disable-next-line @typescript-eslint/naming-convention
export interface GatsbyImageProps
extends Omit<
ImgHTMLAttributes<HTMLImageElement>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ describe(`reverseLookupParams`, () => {
compatiblePath(`/{Model.fields__name}.js`)
)
).toEqual({
// eslint-disable-next-line @typescript-eslint/naming-convention
fields__name: `foo`,
})
expect(
Expand All @@ -224,6 +225,7 @@ describe(`reverseLookupParams`, () => {
compatiblePath(`/{_model.fields__name}.js`)
)
).toEqual({
// eslint-disable-next-line @typescript-eslint/naming-convention
fields__name: `foo`,
})
})
Expand All @@ -236,6 +238,7 @@ describe(`reverseLookupParams`, () => {
compatiblePath(`/{Model.parent__(File)__relativePath}.js`)
)
).toEqual({
// eslint-disable-next-line @typescript-eslint/naming-convention
parent__relativePath: `foo`,
})
expect(
Expand All @@ -245,6 +248,7 @@ describe(`reverseLookupParams`, () => {
compatiblePath(`/{model123.parent__(File)__relativePath}.js`)
)
).toEqual({
// eslint-disable-next-line @typescript-eslint/naming-convention
parent__relativePath: `foo`,
})
})
Expand Down
1 change: 1 addition & 0 deletions packages/gatsby/src/joi-schemas/joi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export const pageSchema: Joi.ObjectSchema<IGatsbyPage> = Joi.object()
component: Joi.string().required(),
componentChunkName: Joi.string().required(),
context: Joi.object(),
// eslint-disable-next-line @typescript-eslint/naming-convention
pluginCreator___NODE: Joi.string(),
pluginCreatorId: Joi.string(),
})
Expand Down
1 change: 1 addition & 0 deletions packages/gatsby/src/redux/plugin-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ interface ICreatePageAction {
id: string
}
updatedAt: number
// eslint-disable-next-line @typescript-eslint/naming-convention
pluginCreator___NODE: string
pluginCreatorId: string
componentPath: string
Expand Down
1 change: 1 addition & 0 deletions packages/gatsby/src/redux/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export interface IGatsbyPage {
isCreatedByStatefulCreatePages: boolean
context: Record<string, unknown>
updatedAt: number
// eslint-disable-next-line @typescript-eslint/naming-convention
pluginCreator___NODE: Identifier
pluginCreatorId: Identifier
componentPath: SystemPath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,7 @@ describe(`Get example value for type inference`, () => {
})
})

/* eslint-disable @typescript-eslint/naming-convention */
describe(`Handles ___NODE foreign-key convenience relations`, () => {
it(`infers single related node id as a simple string`, () => {
const example = getExampleValueWithoutConflicts({
Expand Down Expand Up @@ -719,6 +720,7 @@ describe(`Get example value for type inference`, () => {
expect(example.related___NODE).toEqual(INVALID_VALUE)
})
})
/* eslint-enable @typescript-eslint/naming-convention */

describe(`Incremental example value building`, () => {
const _nodes = [
Expand Down Expand Up @@ -907,6 +909,7 @@ describe(`Type conflicts`, () => {
})

it(`reports on mixed ___NODE fields`, () => {
// eslint-disable-next-line @typescript-eslint/naming-convention
const nodes = [{ related___NODE: `foo` }, { related___NODE: [`bar`] }]

const conflicts = getExampleValueConflicts({
Expand Down Expand Up @@ -1045,7 +1048,9 @@ describe(`Type change detection`, () => {
{ object: { foo: `foo`, bar: `bar` } },
{ list: [`item`], bar: `bar` },
{ listOfObjects: [{ foo: `foo`, bar: `bar` }] },
// eslint-disable-next-line @typescript-eslint/naming-convention
{ relatedNode___NODE: `foo` },
// eslint-disable-next-line @typescript-eslint/naming-convention
{ relatedNodeList___NODE: [`foo`] },
]

Expand Down Expand Up @@ -1142,6 +1147,7 @@ describe(`Type change detection`, () => {
expect(haveEqualFields(metadata, initialMetadata)).toEqual(true)
})

/* eslint-disable @typescript-eslint/naming-convention */
it(`detects on any change of the relatedNode field`, () => {
// We do not know a type of the node being added hence consider and
// add/delete to such fields as mutations
Expand Down Expand Up @@ -1179,6 +1185,7 @@ describe(`Type change detection`, () => {
expect(metadata.dirty).toEqual(false)
expect(haveEqualFields(metadata, initialMetadata)).toEqual(true)
})
/* eslint-enable @typescript-eslint/naming-convention */

it(`does not detect on symmetric add/delete`, () => {
let metadata
Expand Down
1 change: 1 addition & 0 deletions packages/gatsby/src/utils/api-node-docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export const onCreateNode = true
* @example
* exports.unstable_shouldOnCreateNode = ({node}, pluginOptions) => node.internal.type === 'Image'
*/
// eslint-disable-next-line @typescript-eslint/naming-convention
export const unstable_shouldOnCreateNode = true

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/src/utils/fast-refresh-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type Event = [
]

declare global {
// eslint-disable-next-line @typescript-eslint/interface-name-prefix
// eslint-disable-next-line @typescript-eslint/naming-convention
interface Window {
_gatsbyEvents: Array<Event> | { push: (event: Event) => void }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ describe(`CoreJSResolver`, () => {
it(`should convert core-js@2 file to core-js@3`, async () => {
const resolver = new CoreJSResolver()

// eslint-disable-next-line @typescript-eslint/naming-convention
const doResolve = jest.fn((_, request, __, ___, callback) =>
callback(null, slash(request.request))
)
Expand All @@ -48,6 +49,7 @@ describe(`CoreJSResolver`, () => {
it(`should convert es6.regexp.replace to it's corejs@3 equivalent`, async () => {
const resolver = new CoreJSResolver()

// eslint-disable-next-line @typescript-eslint/naming-convention
const doResolve = jest.fn((_, request, __, ___, callback) =>
callback(null, slash(request.request))
)
Expand Down