Skip to content

Commit

Permalink
build(eslint): upgrade to v9 (#6825)
Browse files Browse the repository at this point in the history
* chore: move eslintconfig to eslint.config

* chore: add ignores/investigate carbon config issues

* fix(eslint): filter out repeated ts-eslint plugin definitions

* feat: finish eslint v9 setup

* chore: cleanup extraneous deps

* refactor(eslint): cleanup ignores

* refactor: replace double quotes with singe and bump eslint-config-carbon

* chore: update lock file

* fix(prettier): add mjs extension to prettier list

* chore: revert test for prettier

---------

Co-authored-by: elysia <[email protected]>
  • Loading branch information
matthewgallo and elycheea authored Feb 3, 2025
1 parent 8421533 commit d0b1481
Show file tree
Hide file tree
Showing 19 changed files with 1,288 additions and 408 deletions.
34 changes: 0 additions & 34 deletions .eslintignore

This file was deleted.

60 changes: 0 additions & 60 deletions .eslintrc.js

This file was deleted.

137 changes: 137 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/**
* Copyright IBM Corp. 2025, 2025
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

import globals from 'globals';
import { fixupPluginRules } from '@eslint/compat';
import { FlatCompat } from '@eslint/eslintrc'
import eslint from '@eslint/js';
import react from 'eslint-plugin-react';
import pluginSsrFriendly from 'eslint-plugin-ssr-friendly';
import tsEslint from 'typescript-eslint';

import path from 'node:path'
import { fileURLToPath } from 'node:url'

const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: eslint.configs.recommended,
allConfig: eslint.configs.all,
});

export default tsEslint.config(
...compat.extends('eslint-config-carbon').map(c => {
if (c.plugins?.['@typescript-eslint']) {
return {};
}
return c;
}),
eslint.configs.recommended,
tsEslint.configs.recommended,
react.configs.flat.recommended,
{
files: ['**/*.{js,mjs,cjs,jsx}'],
languageOptions: {
parser: {
meta: {
name: 'Ignore Without Parsing',
},

// Ignore Parsing error
parse: function () {
return {
type: 'Program',
loc: {},
comments: [],
range: [0, 0],
body: [],
tokens: [],
};
},
},
parserOptions: {
sourceType: 'script'
}
},
rules: {
'no-duplicate-imports': 'error',
},
},
{
ignores: [
'build',
'packages/*/build',
'packages/*/lib/*',
'packages/*/es/*',
'packages/*/examples/*/build',
'es',
'lib',
'dist',
'umd',
'examples',
'node_modules',
'packages/*/examples/*',
'**/node_modules/**',
'**/storybook-static/**',
'*.stories.*',
'**/coverage/**',
'packages/ibm-products/scripts/generate/templates/**/*.js*',
'scripts/example-gallery-builder/update-example/**/*.js*',
],
},
{
plugins: {
'ssr-friendly': fixupPluginRules(pluginSsrFriendly),
},
languageOptions: {
globals: {
...globals.browser,
...globals.node,
...globals.jest
}
},
settings: {
react: {
version: 'detect',
},
},
rules: {
'@typescript-eslint/no-require-imports': 'off',
'@typescript-eslint/ban-ts-comment': 0,
'@typescript-eslint/no-explicit-any': 0,
'@typescript-eslint/no-unused-expressions': 0,
'@typescript-eslint/no-unused-vars': 0,
'@typescript-eslint/no-empty-object-type': 2,
'react/display-name': 0,
'react-hooks/exhaustive-deps': 2,
'jsx-a11y/no-noninteractive-tabindex': 1,
'jsx-a11y/no-static-element-interactions': 1,
'jsx-a11y/click-events-have-key-events': 1,
'jsdoc/check-tag-names': ['error', { definedTags: [ 'element', 'slot', 'csspart' ] }],
'ssr-friendly/no-dom-globals-in-module-scope': 2,
'react/prop-types': 2,
'react/forbid-dom-props': [
2,
{
'forbid': [
{
'propName': 'style',
'disallowedFor': [
'Datagrid',
'Carousel',
'Checklist',
'Coachmark'
],
'message': 'Avoid using style prop'
}
]
}
]
},
}
);
17 changes: 12 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,23 +76,29 @@
"@babel/preset-react": "^7.17.12",
"@commitlint/cli": "^18.6.0",
"@commitlint/config-conventional": "^18.6.0",
"@eslint/compat": "^1.2.5",
"@eslint/eslintrc": "^3.2.0",
"@eslint/js": "^9.19.0",
"@playwright/test": "^1.49.1",
"@testing-library/dom": "^8.11.4",
"@testing-library/react": "^14.0.0",
"@testing-library/react-hooks": "^8.0.1",
"@testing-library/user-event": "^14.4.3",
"@types/carbon__layout": "^0.0.3",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
"@typescript-eslint/eslint-plugin": "^8.22.0",
"accessibility-checker": "^3.1.78",
"cheerio": "^1.0.0-rc.12",
"commander": "^12.0.0",
"copyfiles": "^2.4.1",
"cspell": "^8.3.2",
"eslint": "^8.56.0",
"eslint-config-carbon": "3.17.1",
"eslint": "^9.19.0",
"eslint-config-carbon": "^3.19.0",
"eslint-plugin-jsx-a11y": "^6.7.1",
"eslint-plugin-react": "^7.37.4",
"eslint-plugin-react-hooks": "^5.1.0",
"eslint-plugin-ssr-friendly": "^1.3.0",
"gitignore-to-glob": "^0.3.0",
"globals": "^15.14.0",
"globby": "^14.0.0",
"husky": "^9.0.5",
"jest": "^29.7.0",
Expand All @@ -112,6 +118,7 @@
"stylelint": "^16.10.0",
"stylelint-config-carbon": "^1.20.0",
"stylelint-use-logical": "^2.1.2",
"typescript-eslint": "^8.22.0",
"webpack": "^5.96.1"
},
"//resolutions:http-signature": "package 'request' deprecated but still used, asks for http-signature ~1.2.0 which indirectly has vulnerabilities",
Expand All @@ -126,7 +133,7 @@
"ws": "^8.17.1"
},
"lint-staged": {
"!(examples/**/*)**/*.{js,jsx,ts,tsx}": [
"!(examples/**/*)**/*.{js,jsx,ts,tsx,mjs}": [
"npx prettier --cache --write",
"npx eslint --fix",
"npx cspell --no-must-find-files",
Expand Down
4 changes: 2 additions & 2 deletions packages/ibm-products-web-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@
"autoprefixer": "^10.4.20",
"c8": "^10.1.3",
"cssnano": "^7.0.6",
"eslint": "^8.56.0",
"eslint-config-carbon": "3.18.0",
"eslint": "^9.14.0",
"eslint-config-carbon": "^3.19.0",
"globby": "^14.0.2",
"happy-dom": "^15.11.6",
"postcss": "^8.4.47",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ class CDSSidePanel extends HostListenerMixin(LitElement) {
const comparisonResult = (target as Node).compareDocumentPosition(
relatedTarget as Node
);
// eslint-disable-next-line no-bitwise
if (relatedTarget === startSentinelNode || comparisonResult) {
await (this.constructor as typeof CDSSidePanel)._delay();
if (
Expand All @@ -215,9 +214,7 @@ class CDSSidePanel extends HostListenerMixin(LitElement) {
) {
this.focus();
}
}
// eslint-disable-next-line no-bitwise
else if (relatedTarget === endSentinelNode || comparisonResult) {
} else if (relatedTarget === endSentinelNode || comparisonResult) {
await (this.constructor as typeof CDSSidePanel)._delay();
if (
!tryFocusElements(
Expand Down Expand Up @@ -406,7 +403,6 @@ class CDSSidePanel extends HostListenerMixin(LitElement) {
this._hasSubtitle = subtitle.length > 0;
}

// eslint-disable-next-line class-methods-use-this
private _handleActionToolbarChange(e: Event) {
const target = e.target as HTMLSlotElement;
const toolbarActions = target?.assignedElements();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ interface StackState {
all: StackHandler[];
}

// eslint-disable-next-line no-bitwise
const PRECEDING =
// eslint-disable-next-line ssr-friendly/no-dom-globals-in-module-scope
Node.DOCUMENT_POSITION_PRECEDING | Node.DOCUMENT_POSITION_CONTAINS;
// eslint-disable-next-line no-bitwise
const FOLLOWING =
// eslint-disable-next-line ssr-friendly/no-dom-globals-in-module-scope
Node.DOCUMENT_POSITION_FOLLOWING | Node.DOCUMENT_POSITION_CONTAINED_BY;

const blockClass = `${prefix}--tearsheet`;
Expand Down Expand Up @@ -209,7 +209,6 @@ class CDSTearsheet extends HostListenerMixin(LitElement) {
const comparisonResult = (target as Node).compareDocumentPosition(
relatedTarget as Node
);
// eslint-disable-next-line no-bitwise
if (relatedTarget === startSentinelNode || comparisonResult & PRECEDING) {
await (this.constructor as typeof CDSTearsheet)._delay();
if (
Expand All @@ -221,9 +220,7 @@ class CDSTearsheet extends HostListenerMixin(LitElement) {
) {
this.focus();
}
}
// eslint-disable-next-line no-bitwise
else if (
} else if (
relatedTarget === endSentinelNode ||
comparisonResult & FOLLOWING
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
/**
* @license
*
* Copyright IBM Corp. 2021, 2024
* Copyright IBM Corp. 2021, 2025
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

import packageJson from '../../../package.json';

/* eslint-disable max-len */

/**
*
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ ActionSet.validateActions =
const problems = [] as string[];

if (actions > 0) {
// eslint-disable-next-line react/prop-types
const size = sizeFn ? sizeFn(props) : props.size || defaults.size;
const stacking = willStack(size, actions);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/* eslint-disable max-len */

/**
* Copyright IBM Corp. 2024
* Copyright IBM Corp. 2024, 2025
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
Expand Down
Loading

0 comments on commit d0b1481

Please sign in to comment.