Skip to content

Commit bf97b01

Browse files
committed
Merge branch 'integration-shared-config' into tools/slackbot
2 parents 16a459d + b56f6ed commit bf97b01

30 files changed

+1378
-933
lines changed

.changeset/afraid-waves-join.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@lg-tools/lint': minor
3+
---
4+
5+
First pre-release of shared lint tooling. Includes shared config for eslint, prettier & packagejsonlint. Use `lg-lint` to run linters with shared config.

.eslintrc.js

Lines changed: 3 additions & 174 deletions
Original file line numberDiff line numberDiff line change
@@ -1,174 +1,3 @@
1-
module.exports = {
2-
parser: 'babel-eslint',
3-
plugins: ['@emotion', 'simple-import-sort'],
4-
extends: [
5-
'eslint:recommended',
6-
'plugin:react/recommended',
7-
'plugin:react-hooks/recommended',
8-
'plugin:jest/recommended',
9-
'prettier',
10-
'prettier/react',
11-
'plugin:jsx-a11y/recommended',
12-
'plugin:storybook/recommended',
13-
],
14-
parserOptions: {
15-
sourceType: 'module',
16-
ecmaFeatures: {
17-
jsx: true,
18-
},
19-
},
20-
env: {
21-
es6: true,
22-
browser: true,
23-
node: true,
24-
},
25-
settings: {
26-
react: {
27-
version: '16.13.1',
28-
},
29-
},
30-
rules: {
31-
'@emotion/jsx-import': 'error',
32-
'@emotion/pkg-renaming': 'error',
33-
'jest/no-conditional-expect': 'off',
34-
'jest/valid-title': 'off',
35-
// can't detect titles that are string variables
36-
'react/jsx-filename-extension': [
37-
'error',
38-
{
39-
extensions: ['.js', '.tsx'],
40-
},
41-
],
42-
'react/forbid-prop-types': 'warn',
43-
'react-hooks/exhaustive-deps': [
44-
'warn',
45-
{
46-
additionalHooks: '(useIsomorphicLayoutEffect)',
47-
},
48-
],
49-
'react/sort-comp': 'error',
50-
'import/no-extraneous-dependencies': 'off',
51-
'padding-line-between-statements': [
52-
'error',
53-
{
54-
blankLine: 'always',
55-
prev: ['block-like', 'const', 'let', 'if', 'while', 'return'],
56-
next: 'block-like',
57-
},
58-
{
59-
blankLine: 'always',
60-
prev: 'block-like',
61-
next: ['block-like', 'const', 'let', 'case', 'if', 'while', 'return'],
62-
},
63-
],
64-
'no-redeclare': 'off',
65-
// covered by TypeScript
66-
'no-trailing-spaces': 'error',
67-
'no-undef': 'off',
68-
// covered by TypeScript
69-
'no-var': 'warn',
70-
'prefer-const': 'warn',
71-
'no-console': [
72-
'error',
73-
{
74-
allow: ['warn', 'error'],
75-
},
76-
],
77-
// increase the severity of rules so they are auto-fixable
78-
'simple-import-sort/imports': 'error',
79-
'simple-import-sort/exports': 'error',
80-
},
81-
overrides: [
82-
{
83-
files: ['**/*.{ts,tsx}'],
84-
parser: '@typescript-eslint/parser',
85-
plugins: ['@typescript-eslint'],
86-
rules: {
87-
// The regular rule thinks imported types are unused
88-
'no-unused-vars': 'off',
89-
'@typescript-eslint/no-unused-vars': [
90-
'warn',
91-
{
92-
ignoreRestSiblings: true,
93-
argsIgnorePattern: '^_',
94-
varsIgnorePattern: '^_',
95-
caughtErrorsIgnorePattern: '^_',
96-
},
97-
],
98-
'@typescript-eslint/adjacent-overload-signatures': 'error',
99-
'@typescript-eslint/array-type': [
100-
'error',
101-
{
102-
default: 'generic',
103-
},
104-
],
105-
'@typescript-eslint/naming-convention': [
106-
'error',
107-
{
108-
selector: 'class',
109-
format: ['PascalCase'],
110-
},
111-
{
112-
selector: 'interface',
113-
format: ['PascalCase'],
114-
custom: {
115-
regex: '^I[A-Z]',
116-
match: false,
117-
},
118-
},
119-
],
120-
'@typescript-eslint/consistent-type-assertions': [
121-
'error',
122-
{
123-
assertionStyle: 'as',
124-
},
125-
],
126-
'@typescript-eslint/consistent-type-definitions': [
127-
'error',
128-
'interface',
129-
],
130-
'@typescript-eslint/explicit-function-return-type': 'off',
131-
'@typescript-eslint/no-inferrable-types': 'warn',
132-
'simple-import-sort/imports': [
133-
'error',
134-
{
135-
groups: [
136-
// Packages `react` related packages come first.
137-
['^react', '^@?\\w'],
138-
// Internal packages.
139-
['^(@|components)(/.*|$)'],
140-
['^@leafygreen-ui', '^@?\\w'],
141-
// Side effect imports.
142-
['^\\u0000'],
143-
// Parent imports. Put `..` last.
144-
['^\\.\\.(?!/?$)', '^\\.\\./?$'],
145-
// Other relative imports. Put same-folder imports and `.` last.
146-
['^\\./(?=.*/)(?!/?$)', '^\\.(?!/?$)', '^\\./?$'],
147-
// Style imports.
148-
['^.+\\.?(css)$'],
149-
],
150-
},
151-
],
152-
},
153-
},
154-
{
155-
files: ['packages/**/*.spec.{ts,tsx}'],
156-
globals: {
157-
expect: true,
158-
should: true,
159-
jest: true,
160-
},
161-
rules: {
162-
'jest/no-disabled-tests': 'error',
163-
'jest/no-identical-title': 'error',
164-
'jest/valid-expect': 'error',
165-
'jest/expect-expect': [
166-
'warn',
167-
{
168-
assertFunctionNames: ['expect', 'waitForElementToBeRemoved'],
169-
},
170-
],
171-
},
172-
},
173-
],
174-
};
1+
// For VSCode extensions
2+
const eslint = require('@lg-tools/lint/eslint.config');
3+
module.exports = eslint;

.github/workflows/pr.yml

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,6 @@ concurrency:
99
cancel-in-progress: true
1010

1111
jobs:
12-
lint:
13-
name: Check lints
14-
runs-on: ubuntu-latest
15-
steps:
16-
- uses: actions/checkout@v2
17-
18-
- name: Use Node.js 16
19-
uses: actions/setup-node@v3
20-
with:
21-
node-version: '16'
22-
cache: yarn
23-
cache-dependency-path: 'yarn.lock'
24-
25-
- run: yarn install --frozen-lockfile --prefer-offline
26-
27-
- name: lint
28-
run: yarn lint
29-
30-
outputs:
31-
yarn-cache-dir: ${{ steps.get-yarn-cache-dir.outputs.dir }}
32-
3312
build:
3413
name: Build packages
3514
runs-on: ubuntu-latest
@@ -62,6 +41,37 @@ jobs:
6241
if: ${{ steps.build-cache.outputs.cache-hit != 'true' }}
6342
run: yarn build
6443

44+
lint:
45+
name: Check lints
46+
runs-on: ubuntu-latest
47+
needs: [build]
48+
steps:
49+
- uses: actions/checkout@v2
50+
51+
- name: Use Node.js 16
52+
uses: actions/setup-node@v3
53+
with:
54+
node-version: '16'
55+
cache: yarn
56+
cache-dependency-path: 'yarn.lock'
57+
58+
- uses: actions/cache/restore@v3
59+
name: Restore build cache
60+
id: build-cache
61+
with:
62+
path: |
63+
**/dist
64+
!**/node_modules
65+
key: ${{ runner.os }}-build-cache-${{ hashFiles('**/rollup.config.js', '**/babel.config.js', '**/src/', '**/scripts/', '!**/node_modules', '!**/dist') }}
66+
67+
- run: yarn install --frozen-lockfile --prefer-offline
68+
69+
- name: lint
70+
run: yarn lint
71+
72+
outputs:
73+
yarn-cache-dir: ${{ steps.get-yarn-cache-dir.outputs.dir }}
74+
6575
chromatic:
6676
name: Chromatic
6777
runs-on: ubuntu-latest

.npmpackagejsonlintrc.json

Lines changed: 0 additions & 13 deletions
This file was deleted.

.prettierrc

Lines changed: 0 additions & 10 deletions
This file was deleted.

.vscode/settings.json

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
{
2-
"typescript.tsdk": "node_modules/typescript/lib",
2+
"editor.defaultFormatter": "esbenp.prettier-vscode",
33
"editor.formatOnSave": true,
4-
"[typescript]": {
5-
"editor.defaultFormatter": "esbenp.prettier-vscode"
6-
},
7-
"[typescriptreact]": {
8-
"editor.defaultFormatter": "esbenp.prettier-vscode"
9-
}
4+
"typescript.tsdk": "node_modules/typescript/lib",
5+
"prettier.configPath": "node_modules/@lg-tools/lint/config/prettier.config.js",
6+
"eslint.lintTask.enable": true,
7+
"eslint.lintTask.options": "--fix --config node_modules/@lg-tools/lint/eslint.config.js",
8+
"eslint.format.enable": true
109
}

commitlint.config.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

package.json

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,12 @@
1212
"build": "turbo run build tsc",
1313
"build-storybook": "storybook build",
1414
"build:docs": "npx ts-node ./scripts/parse-tsdocs.ts",
15-
"lint": "npm-run-all --parallel lint:*",
16-
"lint:prettier": "prettier --check \"**/*.{js,ts,tsx,mjs,json,md,yml}\"",
17-
"lint:eslint": "eslint \"**/*.{js,ts,tsx}\"",
15+
"lint": "lg-lint",
1816
"chromatic": "npx chromatic",
1917
"clean": "yarn clean:builds && yarn clean:modules",
2018
"clean:builds": "rm -rf packages/*/dist packages/*/tsconfig.tsbuildinfo ./tsconfig.tsbuildinfo packages/**/stories.js",
2119
"clean:modules": "rm -rf node_modules packages/*/node_modules ",
22-
"fix": "npm-run-all --parallel fix:*",
23-
"fix:prettier": "prettier --write \"**/*.{js,ts,tsx,mjs,json,md,yml}\"",
24-
"fix:eslint": "eslint \"**/*.{js,ts,tsx}\" --fix",
20+
"fix": "lg-lint --fix",
2521
"link": "./scripts/link.sh",
2622
"link:all": "lerna exec -- yarn link",
2723
"prepublishOnly": "yarn fix && yarn test && yarn build && yarn prepublish:ts-downlevel",
@@ -37,20 +33,19 @@
3733
"validate": "npm-run-all --parallel validate:*",
3834
"validate:dependencies": "npx ts-node ./scripts/depcheck.ts",
3935
"validate:builds": "npx ts-node ./scripts/check-builds.ts",
40-
"validate:package-json": "npmPkgJsonLint ./packages",
4136
"watch": "yarn build -- -- --watch"
4237
},
4338
"devDependencies": {
4439
"@babel/core": "^7.9.0",
45-
"@changesets/cli": "^2.6.2",
40+
"@changesets/cli": "^2.26.0",
4641
"@emotion/css": "^11.1.3",
47-
"@emotion/eslint-plugin": "^11.2.0",
4842
"@emotion/react": "^11.4.0",
4943
"@emotion/server": "^11.4.0",
5044
"@emotion/styled": "^11.3.0",
5145
"@leafygreen-ui/lib": "^10.1.0",
5246
"@leafygreen-ui/testing-lib": "*",
5347
"@lg-tools/build": "^0.0.1",
48+
"@lg-tools/lint": "^0.0.1",
5449
"@lg-tools/slackbot": "^0.0.1",
5550
"@lg-tools/storybook": "^0.0.1",
5651
"@lg-tools/storybook-decorators": "^0.0.1",
@@ -65,9 +60,7 @@
6560
"@types/react-dom": "^16.9.9",
6661
"@types/react-transition-group": "4.4.1",
6762
"@types/xml2json": "^0.11.0",
68-
"@typescript-eslint/eslint-plugin": "^4.5.0",
69-
"@typescript-eslint/parser": "^4.5.0",
70-
"babel-eslint": "10.1.0",
63+
"babel-jest": "26.0.0",
7164
"buffer": "^6.0.3",
7265
"chromatic": "^6.17.2",
7366
"commander": "^9.4.0",
@@ -76,25 +69,14 @@
7669
"depcheck": "^1.4.3",
7770
"dotenv": "^10.0.0",
7871
"downlevel-dts": "^0.7.0",
79-
"eslint": "7.12.0",
80-
"eslint-config-prettier": "6.14.0",
81-
"eslint-plugin-import": "2.22.1",
82-
"eslint-plugin-jest": "24.1.0",
83-
"eslint-plugin-jsx-a11y": "^6.3.1",
84-
"eslint-plugin-react": "7.21.5",
85-
"eslint-plugin-react-hooks": "^4.2.0",
86-
"eslint-plugin-simple-import-sort": "^8.0.0",
87-
"eslint-plugin-storybook": "^0.6.12",
8872
"gh-pages": "^3.1.0",
8973
"highlight.js": "^11.0.0",
9074
"highlightjs-graphql": "^1.0.1",
9175
"highlightjs-line-numbers.js": "^2.7.0",
9276
"lerna": "^7.0.2",
9377
"meow": "^6.1.0",
9478
"node-fetch": "2",
95-
"npm-package-json-lint": "^6.3.0",
9679
"npm-run-all": "^4.1.5",
97-
"prettier": "^2.0.4",
9880
"prop-types": "^15.7.2",
9981
"react": "^17.0.2",
10082
"react-docgen-typescript": "^2.2.2",

packages/code/src/Code/Code.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ describe('packages/Code', () => {
101101

102102
const copyIcon = screen.getByRole('button');
103103
fireEvent.click(copyIcon);
104-
expect(onCopy).toBeCalledTimes(1);
104+
expect(onCopy).toHaveBeenCalledTimes(1);
105105
});
106106
});
107107

packages/guide-cue/src/GuideCue.spec.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ async function expectElementToNotBeRemoved(element: HTMLElement) {
1717
await waitForElementToBeRemoved(element);
1818
throw new Error('Expected to catch error.');
1919
} catch (error) {
20-
// eslint-disable-next-line jest/no-try-expect
2120
if (error instanceof Error) {
2221
expect(error.toString()).toMatch(
2322
'Timed out in waitForElementToBeRemoved.',

0 commit comments

Comments
 (0)