UNPKG

@elsikora/eslint-config

Version:

ESLint configuration vision of ElsiKora

110 lines (105 loc) 6.65 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var react = require('@eslint-react/eslint-plugin'); require('eslint/use-at-your-own-risk'); var formatConfig_utility = require('../utility/format-config.utility.js'); var formatPluginName_utility = require('../utility/format-plugin-name.utility.js'); var formatRuleName_utility = require('../utility/format-rule-name.utility.js'); var react2 = require('eslint-plugin-react'); var tseslint = require('typescript-eslint'); /** * Loads the ESLint configuration for React applications * @param {IConfigOptions} config - Configuration options * @returns {Array<Linter.Config>} An array of ESLint configurations for React */ function loadConfig(config) { return [ { settings: { react: { version: "detect", }, }, }, { plugins: { [formatPluginName_utility.formatPluginName("react")]: react2, }, }, { // @ts-ignore ...formatConfig_utility.formatConfig([react.configs.recommended])[0], files: ["**/*.js", "**/*.jsx"], languageOptions: { parserOptions: { ecmaFeatures: { jsx: true, }, ecmaVersion: "latest", }, }, }, { files: ["**/*.js", "**/*.jsx", "**/*.ts", "**/*.tsx"], rules: { [formatRuleName_utility.formatRuleName("@eslint-react/hooks-extra/no-direct-set-state-in-use-effect")]: "error", // Disallow direct setState in useEffect [formatRuleName_utility.formatRuleName("@eslint-react/naming-convention/context-name")]: "error", // Enforce the naming of context providers [formatRuleName_utility.formatRuleName("react/checked-requires-onchange-or-readonly")]: "error", // Enforce input elements using either onChange or readOnly [formatRuleName_utility.formatRuleName("react/default-props-match-prop-types")]: config.withNext ? "off" : "error", // Enforce all defaultProps have a corresponding non-required PropType [formatRuleName_utility.formatRuleName("react/function-component-definition")]: [ "error", { namedComponents: "arrow-function", unnamedComponents: "arrow-function", }, ], // Enforce the definition of a component with arrow functions [formatRuleName_utility.formatRuleName("react/jsx-closing-bracket-location")]: "off", // Enforce the closing bracket location for JSX multiline elements [formatRuleName_utility.formatRuleName("react/jsx-curly-brace-presence")]: [ "error", { children: "always", propElementValues: "always", props: "always", }, ], // Enforce curly braces or disallow unnecessary curly braces in JSX props and/or children [formatRuleName_utility.formatRuleName("react/jsx-no-bind")]: "off", // Prevent usage of Function.prototype.bind and arrow functions in React component props [formatRuleName_utility.formatRuleName("react/jsx-no-undef")]: "error", // Disallow undeclared variables in JSX [formatRuleName_utility.formatRuleName("react/no-deprecated")]: "error", // Prevent usage of deprecated methods [formatRuleName_utility.formatRuleName("react/no-invalid-html-attribute")]: "error", // Disallow invalid characters in props [formatRuleName_utility.formatRuleName("react/no-is-mounted")]: "error", // Prevent usage of isMounted [formatRuleName_utility.formatRuleName("react/no-this-in-sfc")]: "error", // Prevent this from being used in stateless functional components [formatRuleName_utility.formatRuleName("react/no-typos")]: "error", // Prevent common typos [formatRuleName_utility.formatRuleName("react/no-unescaped-entities")]: "error", // Disallow unescaped entities [formatRuleName_utility.formatRuleName("react/prefer-stateless-function")]: ["error", { ignorePureComponents: true }], // Enforce stateless components to be written as a pure function [formatRuleName_utility.formatRuleName("react/react-in-jsx-scope")]: config.withNext ? "off" : "error", // Prevent missing React when using JSX [formatRuleName_utility.formatRuleName("react/require-default-props")]: "error", // Enforce a defaultProps definition for every prop that is not a required prop [formatRuleName_utility.formatRuleName("react/require-render-return")]: "error", // Enforce ES5 or ES6 class for returning value in render function [formatRuleName_utility.formatRuleName("react/self-closing-comp")]: "error", // Prevent extra closing tags for components without children [formatRuleName_utility.formatRuleName("react/state-in-constructor")]: ["error", "never"], // Enforce state initialization style [formatRuleName_utility.formatRuleName("react/style-prop-object")]: "error", // Enforce style prop value being an object }, }, { files: ["**/*.jsx", "**/*.tsx"], rules: { [formatRuleName_utility.formatRuleName("@eslint-react/naming-convention/component-name")]: ["error", "PascalCase"], // Enforce component naming conventions [formatRuleName_utility.formatRuleName("@eslint-react/naming-convention/filename-extension")]: ["error", { allow: "as-needed" }], // Enforce filename conventions [formatRuleName_utility.formatRuleName("@eslint-react/naming-convention/filename")]: config.withNext ? "off" : "error", // Enforce filename conventions [formatRuleName_utility.formatRuleName("@eslint-react/naming-convention/use-state")]: "error", // Enforce the use of the useState hook }, }, { // @ts-ignore ...formatConfig_utility.formatConfig([react.configs["recommended-type-checked"]])[0], files: ["**/*.ts", "**/*.tsx"], languageOptions: { parser: tseslint.parser, parserOptions: { projectService: true, }, }, }, ]; } exports.default = loadConfig; //# sourceMappingURL=react.js.map