@elsikora/eslint-config
Version:
ESLint configuration vision of ElsiKora
110 lines (105 loc) • 6.65 kB
JavaScript
'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: {
[]: 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: {
[]: "error", // Disallow direct setState in useEffect
[]: "error", // Enforce the naming of context providers
[]: "error", // Enforce input elements using either onChange or readOnly
[]: config.withNext ? "off" : "error", // Enforce all defaultProps have a corresponding non-required PropType
[]: [
"error",
{
namedComponents: "arrow-function",
unnamedComponents: "arrow-function",
},
], // Enforce the definition of a component with arrow functions
[]: "off", // Enforce the closing bracket location for JSX multiline elements
[]: [
"error",
{
children: "always",
propElementValues: "always",
props: "always",
},
], // Enforce curly braces or disallow unnecessary curly braces in JSX props and/or children
[]: "off", // Prevent usage of Function.prototype.bind and arrow functions in React component props
[]: "error", // Disallow undeclared variables in JSX
[]: "error", // Prevent usage of deprecated methods
[]: "error", // Disallow invalid characters in props
[]: "error", // Prevent usage of isMounted
[]: "error", // Prevent this from being used in stateless functional components
[]: "error", // Prevent common typos
[]: "error", // Disallow unescaped entities
[]: ["error", { ignorePureComponents: true }], // Enforce stateless components to be written as a pure function
[]: config.withNext ? "off" : "error", // Prevent missing React when using JSX
[]: "error", // Enforce a defaultProps definition for every prop that is not a required prop
[]: "error", // Enforce ES5 or ES6 class for returning value in render function
[]: "error", // Prevent extra closing tags for components without children
[]: ["error", "never"], // Enforce state initialization style
[]: "error", // Enforce style prop value being an object
},
},
{
files: ["**/*.jsx", "**/*.tsx"],
rules: {
[]: ["error", "PascalCase"], // Enforce component naming conventions
[]: ["error", { allow: "as-needed" }], // Enforce filename conventions
[]: config.withNext ? "off" : "error", // Enforce filename conventions
[]: "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