Skip to content

Commit ad01b46

Browse files
authored
fix eslint errors (#10)
* fix eslint errors * update prettier and linting rules so that they're compatible * add new eslint rule to README
1 parent 1b80699 commit ad01b46

13 files changed

+139
-76
lines changed

app/.eslintrc.json

+12-8
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
{
2-
"parser": "@typescript-eslint/parser",
3-
"parserOptions": {
4-
"tsconfigRootDir": "__dirname",
5-
"project": ["./tsconfig.json"]
6-
},
7-
"plugins": ["@typescript-eslint"],
2+
"env": {
3+
"jest/globals": true
4+
},
85
"extends": [
96
"plugin:@typescript-eslint/recommended",
107
"plugin:@typescript-eslint/recommended-requiring-type-checking",
11-
"plugin:prettier/recommended",
128
"prettier",
139
"next",
1410
"nava"
1511
],
12+
"parser": "@typescript-eslint/parser",
13+
"parserOptions": {
14+
"tsconfigRootDir": "./",
15+
"project": ["./tsconfig.json"]
16+
},
17+
"plugins": ["@typescript-eslint", "jest"],
1618
"rules": {
1719
"@typescript-eslint/no-unused-vars": "error",
18-
"@typescript-eslint/no-explicit-any": "error"
20+
"@typescript-eslint/no-explicit-any": "error",
21+
"react/react-in-jsx-scope": "off",
22+
"space-before-function-paren": ["error", "never"]
1923
}
2024
}

app/.prettierrc.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"singleQuote": true,
3-
"trailingComma": "all"
2+
"semi": false,
3+
"singleQuote": true
44
}

app/README.md

+28-21
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app). This README has been modified from the auto-generated one.
1+
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app). This README has been modified from the auto-generated one.
22

33
## Getting Started
44

@@ -26,7 +26,7 @@ The `pages/api` directory is mapped to `/api/*`. Files in this directory are tre
2626

2727
### Setting up up linting and typechecking for local development
2828

29-
For linting, this application is leveraging `eslint`, `prettier` and Nava's [eslint-config-nava](https://github.com/navapbc/eslint-config-nava). Although, these will be run on CI and prior to commit, it is still recommended that we tell our code editor to auto-fix eslint and prettier errors on save.
29+
For linting, this application is leveraging `eslint`, `prettier` and Nava's [eslint-config-nava](https://github.com/navapbc/eslint-config-nava). Although, these will be run on CI and prior to commit, it is still recommended that we tell our code editor to auto-fix eslint and prettier errors on save.
3030

3131
In VSCode, do so by creating a `.vscode/settings.json` file with:
3232

@@ -51,41 +51,48 @@ Note: make sure TypeScript and Javascript Language Features are enabled in VS Co
5151
### Eslint rules explained
5252

5353
- "@typescript-eslint/no-unused-vars": "error"
54-
- Disallows unused variables-- prevents dead code accumulation.
54+
- Disallows unused variables-- prevents dead code accumulation.
5555
- "@typescript-eslint/no-explicit-any": "error"
56-
- Disallows usage of `any` type. The usage of `any` defeats the purpose of typescript. Consider using `unknown` type instead instead.
56+
- Disallows usage of `any` type. The usage of `any` defeats the purpose of typescript. Consider using `unknown` type instead instead.
57+
- "react/resct-in-jsx-scope": "off"
58+
- suppress errors for missing 'import React' in files because NextJS does this for us.
59+
- "space-before-function-paren": ["error", "never"]
60+
- suppresses errors for lack of space before function parenthesis to allow for `function()`
5761

5862
### Tsconfig additions to auto-generated file
5963

60-
- `target: es6` -- nextJS set this valule to `es5` by default.
61-
- `allowJS: true` -- allows ts checks on javascript files.
62-
- `checkJS: true` -- works in tandem with `allowJS`. Alternative to adding `// @ts-check` at top of Js files-- instructs ts to check all js files.
64+
- `target: es6` -- nextJS set this valule to `es5` by default.
65+
- `allowJS: true` -- allows ts checks on javascript files.
66+
- `checkJS: true` -- works in tandem with `allowJS`. Alternative to adding `// @ts-check` at top of Js files-- instructs ts to check all js files.
6367
- `jsx: react-jsx` -- [Documentation on this option](https://www.typescriptlang.org/docs/handbook/jsx.html). This value updates the JSX mode that TS whips with. Updating this from "preserve" helped get jest tests into a passing state. TODO: figure out why.
64-
- `incremental: true` -- enables incremental typechecking. Incremental typechecking creates a series of `.tsbuildinfo` files to dave information from last compilation. This expedites type checking during build.
68+
- `incremental: true` -- enables incremental typechecking. Incremental typechecking creates a series of `.tsbuildinfo` files to dave information from last compilation. This expedites type checking during build.
6569
- `baseUrl: "."` & `paths: { @pages/*: [pages/*] }` -- These two, in tandem, setup module path aliases for cleaner imports. To utilize this, import files like: `import Home from "@pages/index";`
6670

67-
### Package.json
71+
### Package.json
6872

6973
#### Scripts
70-
- `format`: instructs prettier to rewrite files with fixes for formatting violations.
71-
- `format-check`: instructs prettier to only check files for violations without fixing them.
72-
- `test`: runs `jest --ci --coverage`. [--ci option](https://jestjs.io/docs/cli#--ci) is provided to prevent automatic creation of snapshots. This requires Jest to be run with `--updateSnapshot`. [--coverage option](https://jestjs.io/docs/cli#--coverageboolean) is provided to instruct jest to collect and report test coverage in output.
73-
- `ts:check`: runs `tsc --noEmit`. [--noEmit option](https://www.typescriptlang.org/tsconfig#noEmit) is provided to prevent type checker compiler from outputting files.
74+
75+
- `format`: instructs prettier to rewrite files with fixes for formatting violations.
76+
- `format-check`: instructs prettier to only check files for violations without fixing them.
77+
- `test`: runs `jest --ci --coverage`. [--ci option](https://jestjs.io/docs/cli#--ci) is provided to prevent automatic creation of snapshots. This requires Jest to be run with `--updateSnapshot`. [--coverage option](https://jestjs.io/docs/cli#--coverageboolean) is provided to instruct jest to collect and report test coverage in output.
78+
- `ts:check`: runs `tsc --noEmit`. [--noEmit option](https://www.typescriptlang.org/tsconfig#noEmit) is provided to prevent type checker compiler from outputting files.
7479

7580
#### Dependencies
76-
- `@typescript-eslint/parser`: implemented in .eslint.json via `"parser": "@typescript-eslint/parser"`. This [plugin](https://www.npmjs.com/package/@typescript-eslint/parser) works in tandem with other plugins to help facilitate the usage of ESlint with TypeScript.
81+
82+
- `@typescript-eslint/parser`: implemented in .eslint.json via `"parser": "@typescript-eslint/parser"`. This [plugin](https://www.npmjs.com/package/@typescript-eslint/parser) works in tandem with other plugins to help facilitate the usage of ESlint with TypeScript.
7783
- `@types/jest-axe`: This package contains type definitions for [jest-axe](https://www.npmjs.com/package/jest-axe).
7884

7985
#### Dev Dependencies
80-
- `@babel/preset-typescript`: This [module](https://babeljs.io/docs/en/babel-preset-typescript) allows us to use babel to transpile TypeScript into Javascript, specifically for [jest testing](https://jestjs.io/docs/getting-started#using-typescript) in our case. Implemented in .babelrc > presets.
81-
- `@testing-library/dom`: This [module](https://github.com/testing-library/dom-testing-library) provides querying fo.
82-
- `@testing-library/jest-dom`: This [module](https://testing-library.com/docs/ecosystem-jest-dom/) is a companion for testing-library/dom-- it provides DOM element matchers for jest.
86+
87+
- `@babel/preset-typescript`: This [module](https://babeljs.io/docs/en/babel-preset-typescript) allows us to use babel to transpile TypeScript into Javascript, specifically for [jest testing](https://jestjs.io/docs/getting-started#using-typescript) in our case. Implemented in .babelrc > presets.
88+
- `@testing-library/dom`: This [module](https://github.com/testing-library/dom-testing-library) provides querying fo.
89+
- `@testing-library/jest-dom`: This [module](https://testing-library.com/docs/ecosystem-jest-dom/) is a companion for testing-library/dom-- it provides DOM element matchers for jest.
8390
- `@testing-library/react`: This [module](https://testing-library.com/docs/react-testing-library/intro/) works in tandem with testing-library/dom to add APIs for testing React components.
8491
- `babel-jest`: This [module](https://www.npmjs.com/package/babel-jest) works to compile JavaScript/Typescript code using babel for testing. Automatically implemented if `jest-cli` is used.
85-
- `eslint`: This [module](https://www.npmjs.com/package/eslint) provides linting. Configuration implemented in .eslintrc.
86-
- `eslint-config-nava`: This [module](https://github.com/navapbc/eslint-config-nava) contains nava's preferred configurations for eslint. It is implemented in .eslintrc > extensions > nava.
92+
- `eslint`: This [module](https://www.npmjs.com/package/eslint) provides linting. Configuration implemented in .eslintrc.
93+
- `eslint-config-nava`: This [module](https://github.com/navapbc/eslint-config-nava) contains nava's preferred configurations for eslint. It is implemented in .eslintrc > extensions > nava.
8794
- `eslint-config-next`: This [module](https://nextjs.org/docs/basic-features/eslint) is automatically installed by nextJS, it includes out of the eslint configuration. Implemented in .eslintrc.json > extends > next.
88-
- `eslint-config-prettier`: This [module](https://github.com/prettier/eslint-config-prettier) turns off eslint rules that may conflict with prettier. Implemented in .eslintrc > extends > prettier.
89-
- `jest-environment-jsdom`: This [module](https://www.npmjs.com/package/jest-environment-jsdom) simulates the DOM for testing. Implemented in jest.config.js > testEnvironment.
95+
- `eslint-config-prettier`: This [module](https://github.com/prettier/eslint-config-prettier) turns off eslint rules that may conflict with prettier. Implemented in .eslintrc > extends > prettier.
96+
- `jest-environment-jsdom`: This [module](https://www.npmjs.com/package/jest-environment-jsdom) simulates the DOM for testing. Implemented in jest.config.js > testEnvironment.
9097
- `prettier`: This [module](https://prettier.io/) is used for code formatting. Implemented in .prettierrc.json.
9198
- `ts-jest`: This [module](https://www.npmjs.com/package/ts-jest) lets ys yse hest to test our project written in TypeScript. Implemented in jest.config.js > preset > ts-jest

app/__mocks__/styleMock.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
module.exports = {};
1+
module.exports = {}

app/jest.config.js

+8-10
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,23 @@ module.exports = {
44
preset: 'ts-jest',
55
testEnvironment: 'jsdom',
66
moduleNameMapper: {
7-
"\\.(css|scss)$": "<rootDir>/__mocks__/styleMock.js", // sets up routing to mocks style sheet
8-
"^@pages(.*)$": "<rootDir>/pages$1" //allows module imports of page components
7+
'\\.(css|scss)$': '<rootDir>/__mocks__/styleMock.js', // sets up routing to mocks style sheet
8+
'^@pages(.*)$': '<rootDir>/pages$1', //allows module imports of page components
99
},
10-
setupFilesAfterEnv: ["<rootDir>/test/jest.setup.js"],
10+
setupFilesAfterEnv: ['<rootDir>/test/jest.setup.js'],
1111
transform: {
1212
'^.+\\.tsx?$': 'ts-jest',
1313
}, //transfrom typescript files to common js for jest compiler
1414
transformIgnorePatterns: [
15-
"/.next/",
16-
"/node_modules/",
17-
"^.+\\.module\\.(css|sass|scss)$"
18-
],
19-
testPathIgnorePatterns: [
20-
"<rootDir>/node_modules/",
15+
'/.next/',
16+
'/node_modules/',
17+
'^.+\\.module\\.(css|sass|scss)$',
2118
],
19+
testPathIgnorePatterns: ['<rootDir>/node_modules/'],
2220
testRegex: "(/test/.*(test|spec))\\.[jt]sx?$",
2321
globals: {
2422
'ts-jest': {
2523
tsconfig: 'tsconfig.ts-jest.json'
2624
}
2725
}
28-
};
26+
}

app/next.config.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ const nextConfig = {
66
locales: ['en-US', 'es-ES'],
77
defaultLocale: 'en-US',
88
localeSubpaths: {
9-
es: "es"
10-
}
9+
es: 'es',
10+
},
1111
},
1212
reactStrictMode: true,
13-
};
13+
}
1414

15-
module.exports = nextConfig;
15+
module.exports = nextConfig

app/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"eslint-config-nava": "^11.0.0",
3838
"eslint-config-next": "12.1.6",
3939
"eslint-config-prettier": "^8.5.0",
40+
"eslint-plugin-jest": "^26.5.3",
4041
"jest": "^28.1.0",
4142
"jest-cli": "^28.1.0",
4243
"jest-environment-jsdom": "^28.1.0",

app/pages/_app.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import '../styles/globals.css';
2-
import type { AppProps } from 'next/app';
1+
import '../styles/globals.css'
2+
import type { AppProps } from 'next/app'
33

44
function MyApp({ Component, pageProps }: AppProps) {
5-
return <Component {...pageProps} />;
5+
return <Component {...pageProps} />
66
}
77

8-
export default MyApp;
8+
export default MyApp

app/pages/api/hello.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
2-
import type { NextApiRequest, NextApiResponse } from 'next';
2+
import type { NextApiRequest, NextApiResponse } from 'next'
33

44
type Data = {
5-
name: string;
6-
};
5+
name: string
6+
}
77

88
export default function handler(
99
req: NextApiRequest,
1010
res: NextApiResponse<Data>
1111
) {
12-
res.status(200).json({ name: 'John Doe' });
12+
res.status(200).json({ name: 'John Doe' })
1313
}

app/pages/index.tsx

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import type { NextPage } from 'next';
2-
import Head from 'next/head';
3-
import styles from '../styles/Home.module.css';
1+
import type { NextPage } from 'next'
2+
import Head from 'next/head'
3+
import styles from '../styles/Home.module.css'
44

55
const Home: NextPage = () => {
66
return (
@@ -27,7 +27,7 @@ const Home: NextPage = () => {
2727
<nav aria-label="Secondary">Placeholder Footer</nav>
2828
</footer>
2929
</div>
30-
);
31-
};
30+
)
31+
}
3232

33-
export default Home;
33+
export default Home

app/test/jest.setup.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require('@testing-library/jest-dom');
2-
const { toHaveNoViolations } = require("jest-axe");
1+
require('@testing-library/jest-dom')
2+
const { toHaveNoViolations } = require('jest-axe')
33

4-
expect.extend(toHaveNoViolations);
4+
expect.extend(toHaveNoViolations)

app/test/pages/index.test.tsx

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
// test/pages/index.test.js
22

3-
import { render, screen } from "@testing-library/react";
4-
import { axe } from "jest-axe";
5-
import Home from "@pages/index";
3+
import { render, screen } from '@testing-library/react'
4+
import { axe } from 'jest-axe'
5+
import Home from '@pages/index'
66

77
describe('Home', () => {
88
it('should render the heading', () => {
9-
render(<Home />);
9+
render(<Home />)
1010

11-
const heading = screen.getByText(/Next.js Template!/i);
11+
const heading = screen.getByText(/Next.js Template!/i)
1212

13-
expect(heading).toBeInTheDocument();
14-
expect(heading).toMatchSnapshot();
15-
});
13+
expect(heading).toBeInTheDocument()
14+
expect(heading).toMatchSnapshot()
15+
})
1616

17-
it("should pass accessibility scan", async () => {
18-
const { container } = render(<Home />);
19-
const results = await axe(container);
17+
it('should pass accessibility scan', async () => {
18+
const { container } = render(<Home />)
19+
const results = await axe(container)
2020

21-
expect(results).toHaveNoViolations();
21+
expect(results).toHaveNoViolations()
2222
})
23-
});
23+
})

app/yarn.lock

+53
Original file line numberDiff line numberDiff line change
@@ -1037,6 +1037,14 @@
10371037
"@typescript-eslint/types" "5.27.0"
10381038
"@typescript-eslint/visitor-keys" "5.27.0"
10391039

1040+
"@typescript-eslint/[email protected]":
1041+
version "5.28.0"
1042+
resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-5.28.0.tgz#ef9a5c68fecde72fd2ff8a84b9c120324826c1b9"
1043+
integrity sha512-LeBLTqF/he1Z+boRhSqnso6YrzcKMTQ8bO/YKEe+6+O/JGof9M0g3IJlIsqfrK/6K03MlFIlycbf1uQR1IjE+w==
1044+
dependencies:
1045+
"@typescript-eslint/types" "5.28.0"
1046+
"@typescript-eslint/visitor-keys" "5.28.0"
1047+
10401048
"@typescript-eslint/[email protected]":
10411049
version "5.27.0"
10421050
resolved "https://registry.yarnpkg.com/@typescript-eslint/type-utils/-/type-utils-5.27.0.tgz#36fd95f6747412251d79c795b586ba766cf0974b"
@@ -1051,6 +1059,11 @@
10511059
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.27.0.tgz#c3f44b9dda6177a9554f94a74745ca495ba9c001"
10521060
integrity sha512-lY6C7oGm9a/GWhmUDOs3xAVRz4ty/XKlQ2fOLr8GAIryGn0+UBOoJDWyHer3UgrHkenorwvBnphhP+zPmzmw0A==
10531061

1062+
"@typescript-eslint/[email protected]":
1063+
version "5.28.0"
1064+
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.28.0.tgz#cffd9bcdce28db6daaa146e48a0be4387a6f4e9d"
1065+
integrity sha512-2OOm8ZTOQxqkPbf+DAo8oc16sDlVR5owgJfKheBkxBKg1vAfw2JsSofH9+16VPlN9PWtv8Wzhklkqw3k/zCVxA==
1066+
10541067
"@typescript-eslint/[email protected]":
10551068
version "5.27.0"
10561069
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.27.0.tgz#7965f5b553c634c5354a47dcce0b40b94611e995"
@@ -1064,6 +1077,19 @@
10641077
semver "^7.3.7"
10651078
tsutils "^3.21.0"
10661079

1080+
"@typescript-eslint/[email protected]":
1081+
version "5.28.0"
1082+
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.28.0.tgz#3487d158d091ca2772b285e67412ff6d9797d863"
1083+
integrity sha512-9GX+GfpV+F4hdTtYc6OV9ZkyYilGXPmQpm6AThInpBmKJEyRSIjORJd1G9+bknb7OTFYL+Vd4FBJAO6T78OVqA==
1084+
dependencies:
1085+
"@typescript-eslint/types" "5.28.0"
1086+
"@typescript-eslint/visitor-keys" "5.28.0"
1087+
debug "^4.3.4"
1088+
globby "^11.1.0"
1089+
is-glob "^4.0.3"
1090+
semver "^7.3.7"
1091+
tsutils "^3.21.0"
1092+
10671093
"@typescript-eslint/[email protected]":
10681094
version "5.27.0"
10691095
resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-5.27.0.tgz#d0021cbf686467a6a9499bd0589e19665f9f7e71"
@@ -1076,6 +1102,18 @@
10761102
eslint-scope "^5.1.1"
10771103
eslint-utils "^3.0.0"
10781104

1105+
"@typescript-eslint/utils@^5.10.0":
1106+
version "5.28.0"
1107+
resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-5.28.0.tgz#b27a136eac300a48160b36d2aad0da44a1341b99"
1108+
integrity sha512-E60N5L0fjv7iPJV3UGc4EC+A3Lcj4jle9zzR0gW7vXhflO7/J29kwiTGITA2RlrmPokKiZbBy2DgaclCaEUs6g==
1109+
dependencies:
1110+
"@types/json-schema" "^7.0.9"
1111+
"@typescript-eslint/scope-manager" "5.28.0"
1112+
"@typescript-eslint/types" "5.28.0"
1113+
"@typescript-eslint/typescript-estree" "5.28.0"
1114+
eslint-scope "^5.1.1"
1115+
eslint-utils "^3.0.0"
1116+
10791117
"@typescript-eslint/[email protected]":
10801118
version "5.27.0"
10811119
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.27.0.tgz#97aa9a5d2f3df8215e6d3b77f9d214a24db269bd"
@@ -1084,6 +1122,14 @@
10841122
"@typescript-eslint/types" "5.27.0"
10851123
eslint-visitor-keys "^3.3.0"
10861124

1125+
"@typescript-eslint/[email protected]":
1126+
version "5.28.0"
1127+
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.28.0.tgz#982bb226b763c48fc1859a60de33fbf939d40a0f"
1128+
integrity sha512-BtfP1vCor8cWacovzzPFOoeW4kBQxzmhxGoOpt0v1SFvG+nJ0cWaVdJk7cky1ArTcFHHKNIxyo2LLr3oNkSuXA==
1129+
dependencies:
1130+
"@typescript-eslint/types" "5.28.0"
1131+
eslint-visitor-keys "^3.3.0"
1132+
10871133
abab@^2.0.5, abab@^2.0.6:
10881134
version "2.0.6"
10891135
resolved "https://registry.yarnpkg.com/abab/-/abab-2.0.6.tgz#41b80f2c871d19686216b82309231cfd3cb3d291"
@@ -1893,6 +1939,13 @@ eslint-plugin-import@^2.25.4, eslint-plugin-import@^2.26.0:
18931939
resolve "^1.22.0"
18941940
tsconfig-paths "^3.14.1"
18951941

1942+
eslint-plugin-jest@^26.5.3:
1943+
version "26.5.3"
1944+
resolved "https://registry.yarnpkg.com/eslint-plugin-jest/-/eslint-plugin-jest-26.5.3.tgz#a3ceeaf4a757878342b8b00eca92379b246e5505"
1945+
integrity sha512-sICclUqJQnR1bFRZGLN2jnSVsYOsmPYYnroGCIMVSvTS3y8XR3yjzy1EcTQmk6typ5pRgyIWzbjqxK6cZHEZuQ==
1946+
dependencies:
1947+
"@typescript-eslint/utils" "^5.10.0"
1948+
18961949
eslint-plugin-jsx-a11y@^6.5.1:
18971950
version "6.5.1"
18981951
resolved "https://registry.yarnpkg.com/eslint-plugin-jsx-a11y/-/eslint-plugin-jsx-a11y-6.5.1.tgz#cdbf2df901040ca140b6ec14715c988889c2a6d8"

0 commit comments

Comments
 (0)