Skip to content

Commit

Permalink
Merge pull request #47 from demonicattack/fix-arca-eslint-plugin-ctx
Browse files Browse the repository at this point in the history
fix(eslint): added a branch to fix an issue with eslint-arca-plugin
  • Loading branch information
demonicattack authored Jan 1, 2025
2 parents e3bd77f + 44b98c6 commit 0351349
Show file tree
Hide file tree
Showing 10 changed files with 344 additions and 300 deletions.
2 changes: 2 additions & 0 deletions configs/eslint/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export default eslint({
* '@arca/curly': 'error',
*/
},
/** @default auto add react rules */
react: false,
},
/** @default true @comments plugin enabled */
comments: {
Expand Down
2 changes: 2 additions & 0 deletions configs/eslint/eslint.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export default eslint({
* '@arca/curly': 'error',
*/
},
/** @default auto add react rules */
react: true,
},
/** @default true @comments plugin enabled */
comments: {
Expand Down
2 changes: 2 additions & 0 deletions configs/eslint/eslint.config.viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export default eslint({
* '@arca/curly': 'error',
*/
},
/** @default auto add react rules */
react: true,
},
/** @default true @comments plugin enabled */
comments: {
Expand Down
4 changes: 2 additions & 2 deletions configs/eslint/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@demonicattack/eslint",
"version": "2.3.1",
"version": "2.4.1",
"type": "module",
"exports": "./dist/index.js",
"main": "./dist/index.js",
Expand All @@ -16,7 +16,7 @@
"build:inspector:dev": "yarn run build:inspector:clean && yarn dlx @eslint/config-inspector build --config eslint.config.viewer.js --base / --outDir .eslint-viewer && yarn dlx serve .eslint-viewer",
"build:inspector:viewer": "yarn dlx @eslint/config-inspector build --config eslint.config.viewer.js --base /shared-configs/ --outDir .eslint-viewer",
"check-types": "tsc --noEmit",
"clean": "rimraf node_modules .yarn .eslint-config-inspector",
"clean": "rimraf node_modules .yarn .eslint-viewer",
"dev": "yarn run typegen && yarn dlx @eslint/config-inspector --config eslint.config.ts",
"format": "prettier --check . --cache --cache-location node_modules/.cache/.prettiercache",
"format:debug": "prettier --check . --cache --cache-location node_modules/.cache/.prettiercache --log-level=debug",
Expand Down
2 changes: 2 additions & 0 deletions configs/eslint/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ const eslint = (
if (enableArca) {
configs.push(
arca({
...isSubOptions(options, 'arca'),
overrides: getOverrides(options, 'arca'),
react: isPackageExists('react'),
}),
);
}
Expand Down
16 changes: 11 additions & 5 deletions configs/eslint/src/configs/arca.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
import { eslintArcaPlugin } from '../plugins';
import type { IOptionsOverrides, TFlatConfigItem } from '../types';
import type { IArca, IOptionsOverrides, TFlatConfigItem } from '../types';

const arca = async (options: IOptionsOverrides = {}): Promise<TFlatConfigItem[]> => {
const { overrides = {} } = options;
import { fixupPluginRules } from '@eslint/compat';

const arca = async (options: IArca & IOptionsOverrides = {}): Promise<TFlatConfigItem[]> => {
const { overrides = {}, react = false } = options;

return [
{
name: '@demonicattack/@arca/rules',
plugins: {
['@arca']: eslintArcaPlugin,
['@arca']: react ? fixupPluginRules(eslintArcaPlugin) : eslintArcaPlugin,
},
rules: {
'@arca/curly': 'error',
'@arca/import-quotes': 'error',
'@arca/jsx-import-react': 'error',
...(react ?
{
'@arca/jsx-import-react': 'error',
}
: {}),
'@arca/jsx-longhand-props': 'error',
'@arca/jsx-no-string-styles': 'error',
'@arca/melted-constructs': 'error',
Expand Down
7 changes: 7 additions & 0 deletions configs/eslint/src/configs/disables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ const disables = async (): Promise<TFlatConfigItem[]> => [
'@react/react-in-jsx-scope': 'off',
},
},
{
name: '@demonicattack/@disables/unicorn',
files: ['vite-env.d.ts'],
rules: {
'@unicorn/prevent-abbreviations': 'off',
},
},
];

export { disables };
6 changes: 2 additions & 4 deletions configs/eslint/src/configs/import.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { eslintImportPlugin, eslintSimpleImportSortPlugin } from '../plugins';
import type { IOptionsImport, IOptionsOverrides, TFlatConfigItem } from '../types';
import { interopDefault, renameAndFilterRules } from '../utils';
import { renameAndFilterRules } from '../utils';

import { airbnbBaseImports } from './airbnb';

const imrt = async (options: IOptionsImport & IOptionsOverrides = {}): Promise<TFlatConfigItem[]> => {
const { airbnb = false, overrides = {}, recommended = true, typescript = false } = options;

const tsParser = await interopDefault(import('@typescript-eslint/parser'));

const recommendedRules = renameAndFilterRules(eslintImportPlugin.flatConfigs.recommended.rules, {
import: '@import',
});
Expand Down Expand Up @@ -93,7 +91,7 @@ const imrt = async (options: IOptionsImport & IOptionsOverrides = {}): Promise<T
...(airbnb ? airbnbBaseImports.settings : {}),
'import/extensions': ['.js', '.jsx', ...(typescript ? ['.ts', '.tsx'] : [])],
'import/parsers': {
[tsParser.meta.name]: ['.ts', '.tsx', '.d.ts'],
'@typescript-eslint/parser': ['.ts', '.tsx', '.d.ts'],
},
'import/resolver': {
node: {
Expand Down
7 changes: 6 additions & 1 deletion configs/eslint/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ interface IOptionsImport {
typescript?: boolean;
}

interface IArca {
react?: boolean;
}

interface IOptionsReact {
a11y?: boolean | TFlatConfigItem['rules'];
airbnb?: boolean | TFlatConfigItem['rules'];
Expand Down Expand Up @@ -91,7 +95,7 @@ interface IOptionsConfig extends IOptionsComponentExtensions, IOptionsProjectTyp
/**
* By default, the plugins is disabled
*/
arca?: boolean | IOptionsOverrides;
arca?: boolean | (IArca & IOptionsOverrides);
/**
* Rename plugins
*/
Expand Down Expand Up @@ -142,6 +146,7 @@ interface IOptionsConfig extends IOptionsComponentExtensions, IOptionsProjectTyp

export type {
Awaitable,
IArca,
IOptionsComponentExtensions,
IOptionsConfig,
IOptionsFiles,
Expand Down
Loading

0 comments on commit 0351349

Please sign in to comment.