From 3e640b43ab8e00f40e4b4f5f01d75ef941b9e299 Mon Sep 17 00:00:00 2001 From: Karl Horky Date: Sat, 11 Nov 2023 19:03:18 +0100 Subject: [PATCH 01/17] Update config to ESLint Flat Config --- index.cjs | 919 --------------------- index.d.cts | 4 - index.d.ts | 4 + index.js | 963 +++++++++++++++++++++++ package.json | 8 +- pnpm-lock.yaml | 38 +- types/@next__eslint-plugin-next.d.ts | 6 + types/eslint-plugin-import.d.ts | 6 + types/eslint-plugin-jsx-a11y.d.ts | 6 + types/eslint-plugin-jsx-expressions.d.ts | 6 + types/eslint-plugin-react-hooks.d.ts | 6 + types/eslint-plugin-react.d.ts | 6 + types/eslint-plugin-security.d.ts | 6 + types/eslint-plugin-unicorn.d.ts | 6 + types/eslint-plugin-upleveled.d.ts | 6 + 15 files changed, 1052 insertions(+), 938 deletions(-) delete mode 100644 index.cjs delete mode 100644 index.d.cts create mode 100644 index.d.ts create mode 100644 index.js create mode 100644 types/@next__eslint-plugin-next.d.ts create mode 100644 types/eslint-plugin-import.d.ts create mode 100644 types/eslint-plugin-jsx-a11y.d.ts create mode 100644 types/eslint-plugin-jsx-expressions.d.ts create mode 100644 types/eslint-plugin-react-hooks.d.ts create mode 100644 types/eslint-plugin-react.d.ts create mode 100644 types/eslint-plugin-security.d.ts create mode 100644 types/eslint-plugin-unicorn.d.ts create mode 100644 types/eslint-plugin-upleveled.d.ts diff --git a/index.cjs b/index.cjs deleted file mode 100644 index 4f7b8ea5..00000000 --- a/index.cjs +++ /dev/null @@ -1,919 +0,0 @@ -/** @type {import('@typescript-eslint/utils').TSESLint.Linter.RuleLevelAndOptions} */ -const noRestrictedSyntaxOptions = [ - 'warn', - // Currently it is not possible to use Markdown eg. links in ESLint warnings / error messages - // - // FIXME: Switch to a custom rule - // https://github.com/upleveled/eslint-config-upleveled/issues/123 - { - selector: - "ExpressionStatement CallExpression[callee.object.name='document'][callee.property.name='querySelector'], VariableDeclaration VariableDeclarator CallExpression[callee.object.name='document'][callee.property.name='querySelector']", - message: `Using document.querySelector() can lead to problems, and is not commonly used in React code - prefer instead usage of basic React patterns such as state and controlled components -https://github.com/reactjs/reactjs.org/issues/4626#issuecomment-1117535930`, - }, - { - selector: - "ExpressionStatement CallExpression[callee.object.name='document'][callee.property.name='querySelectorAll'], VariableDeclaration VariableDeclarator CallExpression[callee.object.name='document'][callee.property.name='querySelectorAll']", - message: `Using document.querySelectorAll() can lead to problems, and is not commonly used in React code - prefer instead usage of basic React patterns such as state and controlled components -https://github.com/reactjs/reactjs.org/issues/4626#issuecomment-1117535930`, - }, - { - selector: - "ExpressionStatement CallExpression[callee.object.name='document'][callee.property.name='getElementById'], VariableDeclaration VariableDeclarator[init.callee.object.name!='ReactDOM'][init.callee.property.name!='createRoot'] CallExpression[callee.object.name='document'][callee.property.name='getElementById']", - message: `Using document.getElementById() can lead to problems, and is not commonly used in React code - prefer instead usage of basic React patterns such as state and controlled components -https://github.com/reactjs/reactjs.org/issues/4626#issuecomment-1117535930`, - }, - - // Currently it is not possible to use Markdown eg. links in ESLint warnings / error messages - // - // FIXME: Switch to a custom rule - // https://github.com/upleveled/eslint-config-upleveled/issues/126 - { - selector: - 'FunctionDeclaration VariableDeclaration:has(VariableDeclarator > TaggedTemplateExpression > MemberExpression[object.name="styled"][property]), FunctionDeclaration VariableDeclaration:has(VariableDeclarator > TaggedTemplateExpression[tag.name="css"])', - message: - 'Declaring Emotion styles or a styled component within a React component will cause the element to get recreated, causing loss of state and other problems - see the react/no-unstable-nested-components docs for more info https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/no-unstable-nested-components.md', - }, - - { - selector: - "ExpressionStatement CallExpression[callee.object.name='location'][callee.property.name='reload']", - message: - 'Update content and elements with React instead of using location.reload()', - }, - { - selector: - "ExpressionStatement CallExpression[callee.object.object.name='window'][callee.object.property.name='location'][callee.property.name='reload']", - message: - 'Update content and elements with React instead of using location.reload()', - }, - - { - selector: - "JSXAttribute[name.name='href'] > Literal[value=/^\\./], JSXAttribute[name.name='href'] > JSXExpressionContainer > TemplateLiteral TemplateElement:first-child[value.cooked=/^\\./]", - message: - 'Always start href relative URLs with a forward slash (aka use root relative URLs) - read more at https://www.webdevbydoing.com/absolute-relative-and-root-relative-file-paths/', - }, - - { - selector: - "JSXAttribute[name.name='key'] > JSXExpressionContainer > :not(TemplateLiteral)", - message: - // eslint-disable-next-line no-template-curly-in-string -- Allow for the code example including template strings and interpolation - 'Use template literals including a prefixes for the values of key props (eg.
instead of
)', - }, - - // Warn on nesting elements,