@boehringer-ingelheim/eslint-config
Version:
Shared eslint configuration used at Boehringer Ingelheim for code styling
115 lines • 5.47 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const eslint_plugin_jsx_a11y_1 = __importDefault(require("eslint-plugin-jsx-a11y"));
const eslint_plugin_react_1 = __importDefault(require("eslint-plugin-react"));
const eslint_plugin_react_hooks_1 = __importDefault(require("eslint-plugin-react-hooks"));
const eslint_plugin_react_refresh_1 = require("eslint-plugin-react-refresh");
const config_1 = require("eslint/config");
const globals_1 = __importDefault(require("globals"));
const eslint_plugin_perfectionist_js_1 = require("../lib/eslint-plugin-perfectionist.js");
const base_js_1 = __importDefault(require("./base.js"));
const reactRecommendedConfig = eslint_plugin_react_1.default.configs.flat['recommended'];
if (!reactRecommendedConfig) {
throw new Error('Expected to find the "flat/recommended" configuration in the eslint-plugin-react plugin, but it was not found.');
}
const reactJsxRuntimeConfig = eslint_plugin_react_1.default.configs.flat['jsx-runtime'];
if (!reactJsxRuntimeConfig) {
throw new Error('Expected to find the "flat/jsx-runtime" configuration in the eslint-plugin-react plugin, but it was not found.');
}
exports.default = (0, config_1.defineConfig)(...base_js_1.default, eslint_plugin_jsx_a11y_1.default.flatConfigs.recommended, reactRecommendedConfig, reactJsxRuntimeConfig, eslint_plugin_react_refresh_1.reactRefresh.configs.recommended(), {
languageOptions: {
globals: {
...globals_1.default.browser,
},
parserOptions: {
ecmaFeatures: {
jsx: true,
},
},
},
plugins: {
'react-hooks': {
...eslint_plugin_react_hooks_1.default,
// the eslint-plugin-react-hooks package has some issues with the configs property as it offers the flat configs as a subproperty,
// which makes the config property type incompatible with the ESLint plugin definition.
// We just need the rules, so we can ignore the configs property.
configs: undefined,
},
},
rules: {
// @typescript-eslint: https://github.com/typescript-eslint/typescript-eslint/tree/main/packages/eslint-plugin/docs/rules
'@typescript-eslint/consistent-type-definitions': ['error', 'type'],
'@typescript-eslint/no-restricted-types': [
'error',
{
types: {
'React.FC': {
message: 'Please use object type destructure declaration, see: https://react-typescript-cheatsheet.netlify.app/docs/basic/getting-started/function_components',
},
'React.FunctionalComponent': {
message: 'Please use object type destructure declaration, see: https://react-typescript-cheatsheet.netlify.app/docs/basic/getting-started/function_components',
},
},
},
],
// eslint-plugin-react: https://github.com/jsx-eslint/eslint-plugin-react/tree/master/lib/rules
'react/jsx-pascal-case': 'error',
'react/jsx-sort-props': 'off', // disabled due to conflict with eslint-plugin-perfectionist
'react/sort-default-props': 'error',
// eslint-plugin-react-hooks: https://github.com/facebook/react/blob/main/packages/eslint-plugin-react-hooks/README.md
'react-hooks/exhaustive-deps': 'error',
'react-hooks/rules-of-hooks': 'error',
// eslint-plugin-perfectionist: https://github.com/azat-io/eslint-plugin-perfectionist
'perfectionist/sort-imports': [
'error',
{
customGroups: [
{
elementNamePattern: ['^react$'],
groupName: 'react',
},
],
groups: ['react', ...eslint_plugin_perfectionist_js_1.SORT_IMPORTS_GROUPS],
newlinesBetween: 0, // No newlines are allowed between groups
},
],
'perfectionist/sort-jsx-props': [
'error',
{
customGroups: [
{
elementNamePattern: '^on.+',
groupName: 'callback',
},
{
elementNamePattern: ['children', 'dangerouslySetInnerHTML', 'key', 'ref'], // Reserved props from: https://github.com/jsx-eslint/eslint-plugin-react/blob/master/lib/rules/jsx-sort-props.js#L41-L46
groupName: 'reservedProps',
},
],
groups: ['reservedProps', 'unknown', 'callback'],
},
],
// eslint-plugin-react-refresh: https://github.com/ArnaudBarre/eslint-plugin-react-refresh
'react-refresh/only-export-components': 'warn',
// Forbid enum declaration
'no-restricted-syntax': [
'error',
{
message: "Don't declare enums",
selector: 'TSEnumDeclaration',
},
],
},
settings: {
perfectionist: {
...eslint_plugin_perfectionist_js_1.PERFECTIONIST_SETTINGS,
},
react: {
version: 'detect',
},
},
});
//# sourceMappingURL=react.js.map