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

[DO NOT MERGE] Update eslint -- noteworthy non-linter changes #1130

Closed
wants to merge 5 commits into from
Closed
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
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module.exports = {
root: true,
plugins: ['header'],
rules: {
'header/header': [
2,
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
},
"devDependencies": {
"commander": "^2.20.3",
"eslint-plugin-header": "^3.1.1",
"lerna": "^6.6.1",
"semver": "^7.3.8",
"shelljs": "^0.8.5"
Expand Down
3 changes: 2 additions & 1 deletion packages/commerce-sdk-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"format": "internal-lib-build format \"**/*.{js,jsx,ts,tsx}\"",
"lint": "npm run lint:js && tsc --noEmit",
"lint:fix": "npm run lint:js -- --fix",
"lint:js": "internal-lib-build lint \"**/*.{js,jsx,ts,tsx}\"",
"lint:js": "pwa-kit-dev lint \"**/*.{js,jsx,ts,tsx}\"",
"prepare": "npm run build",
"test": "internal-lib-build test",
"test:inspect": "node --inspect-brk jest --runInBand",
Expand Down Expand Up @@ -60,6 +60,7 @@
"internal-lib-build": "2.8.0-dev",
"jsonwebtoken": "^8.5.1",
"nock": "^13.3.0",
"pwa-kit-dev": "2.8.0-dev",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-helmet": "^6.1.0",
Expand Down
17 changes: 17 additions & 0 deletions packages/commerce-sdk-react/src/hooks/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright (c) 2023, Salesforce, Inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
module.exports = {
rules: {
'jest/expect-expect': [
'error',
{
// Additional helpers used in ./Shopper*/query.test.ts
assertFunctionNames: ['expect', 'waitAndExpectError', 'waitAndExpectSuccess']
}
]
}
}
9 changes: 9 additions & 0 deletions packages/internal-lib-build/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* Copyright (c) 2021, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
module.exports = {
extends: require.resolve('pwa-kit-dev/configs/eslint/eslint-config')
}
18 changes: 1 addition & 17 deletions packages/internal-lib-build/bin/internal-lib-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
/* eslint-disable @typescript-eslint/no-var-requires */
const p = require('path')
const program = require('commander')
const sh = require('shelljs')
Expand All @@ -17,8 +18,6 @@ const execSync = (cmd, opts) => {
return _execSync(cmd, {...defaults, ...opts})
}

const pkgRoot = p.join(__dirname, '..')

const binDir = p.join(require.resolve('@babel/cli'), '..', '..', '..', '.bin')

const main = () => {
Expand All @@ -37,21 +36,6 @@ const main = () => {
execSync(`node ${prepareDist}`)
})

program
.command('lint')
.argument('<path>', 'path or glob to lint')
.option('--fix', 'Try and fix errors (default: false)')
.action((path, {fix}) => {
const eslint = p.join(binDir, 'eslint')
const eslintConfig = p.resolve(p.join(__dirname, '..', 'configs', '.eslintrc.js'))

execSync(
`${eslint} --config ${eslintConfig} --resolve-plugins-relative-to ${pkgRoot}${
fix ? ' --fix' : ''
} "${path}"`
)
})

program
.command('format')
.argument('<path>', 'path or glob to format')
Expand Down
46 changes: 0 additions & 46 deletions packages/internal-lib-build/configs/.eslintrc.js

This file was deleted.

3 changes: 2 additions & 1 deletion packages/internal-lib-build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"format": "node ./bin/internal-lib-build.js format \"**/*.{js,jsx}\"",
"lint": "npm run lint:js",
"lint:fix": "npm run lint:js -- --fix",
"lint:js": "node ./bin/internal-lib-build.js lint ."
"lint:js": "pwa-kit-dev lint ."
},
"dependencies": {
"@babel/cli": "^7.21.0",
Expand Down Expand Up @@ -72,6 +72,7 @@
},
"devDependencies": {
"npm-packlist": "^4.0.0",
"pwa-kit-dev":"2.8.0-dev",
"typescript": "4.8.3"
},
"peerDependencies": {
Expand Down
3 changes: 2 additions & 1 deletion packages/pwa-kit-create-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"format": "internal-lib-build format \"**/*.{js,jsx}\"",
"lint": "npm run lint:js",
"lint:fix": "npm run lint:js -- --fix",
"lint:js": "internal-lib-build lint .",
"lint:js": "pwa-kit-dev lint .",
"prepare": "node scripts/build.js",
"test": "internal-lib-build test"
},
Expand All @@ -36,6 +36,7 @@
},
"devDependencies": {
"internal-lib-build": "2.8.0-dev",
"pwa-kit-dev": "2.8.0-dev",
"verdaccio": "^5.22.1"
},
"engines": {
Expand Down
9 changes: 9 additions & 0 deletions packages/pwa-kit-dev/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* Copyright (c) 2023, Salesforce, Inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
module.exports = {
extends: './dist/configs/eslint/eslint-config.js'
}
42 changes: 30 additions & 12 deletions packages/pwa-kit-dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@
"build": "cross-env NODE_ENV=production internal-lib-build build",
"build:watch": "watch 'npm run build' src/ bin/",
"format": "internal-lib-build format \"**/*.{js,jsx}\"",
"lint": "npm run lint:js",
"lint": "npm run lint:js && npm run typecheck",
"lint:fix": "npm run lint:js -- --fix",
"lint:js": "internal-lib-build lint .",
"lint:js": "eslint .",
"prepare": "npm run build",
"test": "internal-lib-build test",
"typecheck": "tsc --noEmit",
"version": "node ./scripts/version.js"
},
"dependencies": {
Expand All @@ -41,7 +42,6 @@
"@babel/parser": "^7.21.3",
"@babel/plugin-proposal-object-rest-spread": "^7.20.7",
"@babel/plugin-transform-async-to-generator": "^7.20.7",
"@babel/plugin-transform-modules-commonjs": "^7.21.2",
"@babel/plugin-transform-object-assign": "^7.18.6",
"@babel/plugin-transform-runtime": "^7.21.0",
"@babel/preset-env": "^7.20.2",
Expand All @@ -55,6 +55,8 @@
"@loadable/server": "^5.15.3",
"@loadable/webpack-plugin": "^5.15.2",
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.10",
"@typescript-eslint/eslint-plugin": "^5.57.0",
"@typescript-eslint/parser": "^5.57.0",
"archiver": "1.3.0",
"babel-jest": "^26.6.3",
"babel-loader": "^8.3.0",
Expand All @@ -65,16 +67,16 @@
"compression": "1.7.4",
"copy-webpack-plugin": "^9.1.0",
"cross-env": "^5.2.1",
"eslint": "7.32.0",
"eslint-config-prettier": "4.3.0",
"eslint-import-resolver-webpack": "0.13.2",
"eslint-plugin-header": "^3.1.1",
"eslint-plugin-import": "2.27.5",
"eslint": "^8.37.0",
"eslint-config-prettier": "8.8.0",
"eslint-plugin-jest": "^27.2.1",
"eslint-plugin-jsx-a11y": "6.7.1",
"eslint-plugin-prettier": "3.4.1",
"eslint-plugin-prettier": "4.2.1",
"eslint-plugin-react": "^7.32.2",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-use-effect-no-deps": "^1.1.2",
"express": "^4.18.2",
"fs-extra": "^10.1.0",
"fs-extra": "^11.1.1",
"git-rev-sync": "^3.0.2",
"glob": "7.2.3",
"ignore-loader": "^0.1.2",
Expand All @@ -86,6 +88,7 @@
"jest-fetch-mock": "^2.1.2",
"mime-types": "2.1.35",
"minimatch": "3.1.2",
"node-fetch": "^2.6.9",
"open": "^8.4.2",
"prettier": "^2.8.6",
"pwa-kit-runtime": "2.8.0-dev",
Expand All @@ -108,13 +111,28 @@
},
"devDependencies": {
"@loadable/component": "^5.15.3",
"@types/archiver": "^1.3.0",
"@types/fs-extra": "^11.0.1",
"@types/git-rev-sync": "^2.0.0",
"@types/node-fetch": "^2.6.3",
"@types/validator": "^13.7.14",
"internal-lib-build": "2.8.0-dev",
"nock": "^13.3.0",
"superagent": "^6.1.0",
"supertest": "^4.0.2"
"supertest": "^4.0.2",
"typescript": "4.8.3"
},
"peerDependencies": {
"@loadable/component": "^5.15.0"
"@loadable/component": "^5.15.0",
"typescript": ">=4.8.3"
},
"peerDependenciesMeta": {
"@loadable/component": {
"optional": true
},
"typescript": {
"optional": true
}
},
"engines": {
"node": "^16.0.0 || ^18.0.0",
Expand Down
62 changes: 52 additions & 10 deletions packages/pwa-kit-dev/src/configs/eslint/eslint-config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* Copyright (c) 2021, salesforce.com, inc.
* Copyright (c) 2023, Salesforce, Inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
module.exports = {
parser: '@babel/eslint-parser',
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 2017,
sourceType: 'module',
Expand All @@ -16,19 +16,61 @@ module.exports = {
env: {
es6: true,
node: true,
browser: true,
jest: true
browser: true
},
extends: ['eslint:recommended', 'plugin:react/recommended', 'prettier', 'prettier/react'],
plugins: ['header', 'react', 'prettier'],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:react/recommended',
'plugin:jsx-a11y/recommended',
'plugin:prettier/recommended'
],
plugins: ['jsx-a11y', 'prettier', 'react', 'react-hooks', 'use-effect-no-deps'],
settings: {
react: {
version: 'detect'
}
},
reportUnusedDisableDirectives: true,
rules: {
'prettier/prettier': ['error'],
'no-console': 'off',
'no-unused-vars': ['error', {ignoreRestSiblings: true}]
}
'react-hooks/rules-of-hooks': 'error',
// react-hooks/exhaustive-deps has too many false positives; use-effect-no-deps is nicer
'use-effect-no-deps/use-effect-no-deps': 'warn'
},
overrides: [
{
// Jest (v29) default test match pattern
files: ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[jt]s?(x)'],
plugins: ['jest'],
extends: ['plugin:jest/recommended', 'plugin:jest/style'],
rules: {
'jest/expect-expect': [
'warn',
{
// Anything starting with `expect` counts as an assertion
assertFunctionNames: ['expect*', '**.expect*']
}
],
// This doesn't reliably report all errors :/
'jest/no-standalone-expect': ['off']
}
},
{
files: ['**/*.ts', '**/*.tsx'],
extends: ['plugin:@typescript-eslint/recommended-requiring-type-checking'],
rules: {
// These rules all deal with the `any` type in some capacity;
// we want to be more permissive than @typescript-eslint is by default
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-return': 'off'
},
parserOptions: {
project: true
}
}
]
}
Loading