Skip to content

Commit

Permalink
BREAKING CHANGE: Use linz eslint, fix errors
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Use linz eslint, fix errors

Update libs.
Add linz eslint and fix warnings.

Probably not breaking change, but just in case.

BREAKING CHANGE: Use linz eslint, fix errors
  • Loading branch information
matttdawson authored Jan 30, 2025
1 parent 9987f27 commit 92937dd
Show file tree
Hide file tree
Showing 169 changed files with 3,331 additions and 4,983 deletions.
106 changes: 24 additions & 82 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,95 +1,37 @@
// This config will run in a way that fails a build
module.exports = {
env: { commonjs: true, es2020: true, node: true },
plugins: ["react", "react-hooks", "jest", "jsx-a11y", "testing-library"],
settings: {
react: { version: "detect" },
jest: {
version: 26,
},
},
parserOptions: {
ecmaVersion: 2020,
sourceType: "module",
},
extends: [
"eslint:recommended",
"plugin:react/recommended",
"plugin:react-hooks/recommended",
"plugin:jest/recommended",
"plugin:jest/style",
"plugin:testing-library/react",
"plugin:storybook/recommended",
"plugin:prettier/recommended"
],
ignorePatterns: ["react-app-env.d.ts"],
rules: {
// testing-library - to fix
"testing-library/no-dom-import": "off",

// Fix these
"jest/no-conditional-expect": "off",
"jest/no-standalone-expect": "off",
"jest/valid-expect": "off",
"jest/prefer-to-be": "error",
"testing-library/no-await-sync-events": "off",
"testing-library/no-unnecessary-act": "off",
"testing-library/prefer-presence-queries": "off",
"testing-library/no-wait-for-multiple-assertions": "off",
"testing-library/no-render-in-setup": "off",
"testing-library/no-node-access": "off",
"testing-library/prefer-screen-queries": "off",
"testing-library/prefer-find-by": "off",
"testing-library/prefer-query-by-disappearance": "off",
"testing-library/no-debugging-utils": "warn",
"testing-library/render-result-naming-convention": "off",

// customized rules
"react/no-unescaped-entities": ["error", { forbid: [">", '"', "}"] }], // ' is ok, don't want to escape this
"react/react-in-jsx-scope": "off", // TS config takes care of this
"linebreak-style": ["error", "unix"], // prevent crlf from getting pushed
"react/prop-types": "off", // Doesn't seem pick up React.FC<Props> typing
"no-console": ["error", { allow: ["warn", "error"] }], // error on push/codacy
"jest/no-disabled-tests": "warn", // we have some disabled tests
"no-unused-vars": "off", // duplicate of typescript rule
"react/jsx-no-target-blank": "off",
"jest/expect-expect": "off", // sometimes the assertions are in other functions called from a test
extends: ['./node_modules/@linzjs/style/.eslintrc.cjs'],

"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": [
"warn",
{
additionalHooks: "(useWorkflowEffect|useWorkflowSidePanelHook)",
},
],
},
overrides: [
{
/** Overrides for typescript */
files: ["**/*.ts", "**/*.tsx"],
plugins: ["@typescript-eslint"],
parser: "@typescript-eslint/parser",
parserOptions: {
project: "./tsconfig.json",
tsconfigRootDir: __dirname,
},
extends: ["plugin:@typescript-eslint/recommended"],
files: ['**/*.ts', '**/*.tsx'],
rules: {
"@typescript-eslint/await-thenable": "error",
"@typescript-eslint/no-unnecessary-type-constraint": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-empty-function": ["warn", { allow: ["arrowFunctions"] }],
"@typescript-eslint/no-unused-vars": ["error", { argsIgnorePattern: "^_" }], // prepend var with _ (e.g.. _myVar) to ignore this pattern
"@typescript-eslint/no-use-before-define": "off", // We will want to use before define to keep exports at the top
"@typescript-eslint/ban-ts-comment": "off", // We use explicit overrides
"@typescript-eslint/naming-convention": "off", // React's convention is to use CamelCase for component file names
'react/react-in-jsx-scope': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unused-vars': [
'warn',
{
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_',
},
],
'react/prop-types': 'off',
eqeqeq: 'off',
},
},
{
files: ["*.test.js", "*.test.ts", "*.test.tsx", "scripts/*"],
/** Overrides for typescript */
files: ['**/*.stories.tsx'],
rules: {
"no-console": "off",
'@typescript-eslint/no-floating-promises': 'off',
eqeqeq: 'off',
},
},
],
Expand Down
13 changes: 1 addition & 12 deletions .prettierrc.cjs
Original file line number Diff line number Diff line change
@@ -1,12 +1 @@
module.exports = {
semi: true,
trailingComma: "all",
printWidth: 120,
useTabs: false,
tabWidth: 2,
singleQuote: false,
endOfLine: "lf",
importOrder: ["^(.*).(.?)css$", "<THIRD_PARTY_MODULES>", "^@linzjs/(.*)$", "^@step-ag-grid", "^[./]"],
importOrderSortSpecifiers: true,
importOrderSeparation: true,
};
module.exports = { ...require('@linzjs/style/.prettierrc.cjs') };
12 changes: 6 additions & 6 deletions config/jest/babelTransform.cjs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
"use strict";
'use strict';

const babelJest = require("babel-jest");
const babelJest = require('babel-jest');

const hasJsxRuntime = (() => {
if (process.env.DISABLE_NEW_JSX_TRANSFORM === "true") {
if (process.env.DISABLE_NEW_JSX_TRANSFORM === 'true') {
return false;
}

try {
require.resolve("react/jsx-runtime");
require.resolve('react/jsx-runtime');
return true;
} catch (e) {
return false;
Expand All @@ -18,9 +18,9 @@ const hasJsxRuntime = (() => {
module.exports = babelJest.default.createTransformer({
presets: [
[
require.resolve("babel-preset-react-app"),
require.resolve('babel-preset-react-app'),
{
runtime: hasJsxRuntime ? "automatic" : "classic",
runtime: hasJsxRuntime ? 'automatic' : 'classic',
},
],
],
Expand Down
26 changes: 14 additions & 12 deletions jest.config.cjs
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
module.exports = {
roots: ["<rootDir>/src"],
collectCoverageFrom: ["src/**/*.{js,jsx,ts,tsx}", "!src/**/*.d.ts"],
setupFiles: ["react-app-polyfill/jsdom"],
setupFilesAfterEnv: ["jest-expect-message", "<rootDir>/config/jest/setup.js", "<rootDir>/setupTests.js"],
testMatch: ["<rootDir>/src/**/*.{spec,test}.{js,jsx,ts,tsx}"],
testEnvironment: "jsdom",
roots: ['<rootDir>/src'],
collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}', '!src/**/*.d.ts'],
setupFiles: ['react-app-polyfill/jsdom'],
setupFilesAfterEnv: ['jest-expect-message', '<rootDir>/config/jest/setup.js', '<rootDir>/setupTests.js'],
testMatch: ['<rootDir>/src/**/*.{spec,test}.{js,jsx,ts,tsx}'],
testEnvironment: 'jsdom',
transform: {
"^.+\\.(js|jsx|mjs|cjs|ts|tsx)$": "<rootDir>/config/jest/babelTransform.cjs",
"^.+\\.css$": "<rootDir>/config/jest/cssTransform.cjs",
"^(?!.*\\.(js|jsx|mjs|cjs|ts|tsx|css|json)$)": "<rootDir>/config/jest/fileTransform.cjs",
'^.+\\.(js|jsx|mjs|cjs|ts|tsx)$': '<rootDir>/config/jest/babelTransform.cjs',
'^.+\\.css$': '<rootDir>/config/jest/cssTransform.cjs',
'^(?!.*\\.(js|jsx|mjs|cjs|ts|tsx|css|json)$)': '<rootDir>/config/jest/fileTransform.cjs',
},
transformIgnorePatterns: ["node_modules/(?!(ol|@geoblocks/ol-maplibre-layer|geotiff|quick-lru)|lodash-es|lodash|escape-string-regexp|matcher/)"],
transformIgnorePatterns: [
'node_modules/(?!(ol|@geoblocks/ol-maplibre-layer|geotiff|quick-lru)|lodash-es|lodash|escape-string-regexp|matcher/)',
],
moduleNameMapper: {
"^@components/(.*)$": "<rootDir>/src/components/$1",
'^@components/(.*)$': '<rootDir>/src/components/$1',
},
resetMocks: true,
coverageReporters: ["text", "cobertura"],
coverageReporters: ['text', 'cobertura'],
};
Loading

0 comments on commit 92937dd

Please sign in to comment.