Skip to content

Commit

Permalink
refactor: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Airkro committed Jan 8, 2025
1 parent 5e5f8a4 commit de61e7a
Show file tree
Hide file tree
Showing 9 changed files with 2,110 additions and 582 deletions.
47 changes: 32 additions & 15 deletions .best-shot/config.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { RsdoctorWebpackPlugin } from '@rsdoctor/webpack-plugin';
import { Json } from 'fs-chain';

new Json(process.cwd())
Expand All @@ -16,20 +17,36 @@ export const config = {
path: 'dist',
module: true,
},
externals: {
'@yarnpkg/lockfile': 'node-commonjs @yarnpkg/lockfile',
'eslint-module-utils/resolve':
'node-commonjs eslint-module-utils/resolve.js',
// 'flat-cache': 'node-commonjs flat-cache',
'postcss-sass': 'node-commonjs postcss-sass',
'postcss-styl': 'node-commonjs postcss-styl',
// 'write-file-atomic': 'node-commonjs write-file-atomic',
eslint: 'module eslint',
stylelint: 'module stylelint',
sugarss: 'node-commonjs sugarss',
'stylelint-scss/src/rules/dollar-variable-empty-line-before/index.js':
'node-commonjs stylelint-scss/src/rules/dollar-variable-empty-line-before/index.js',
'stylelint-scss/src/rules/double-slash-comment-empty-line-before/index.js':
'node-commonjs stylelint-scss/src/rules/double-slash-comment-empty-line-before/index.js',
externals: [
'@eslint-community/eslint-utils',
'@stylistic/eslint-plugin-js',
'@stylistic/eslint-plugin-jsx',
'@stylistic/eslint-plugin-ts',
'@typescript-eslint/parser',
'eslint-scope',
'eslint',
'eslint/use-at-your-own-risk',
'stylelint',
'typescript',
'vue-eslint-parser',
'eslint-module-utils',
{
'@yarnpkg/lockfile': 'node-commonjs @yarnpkg/lockfile',
'postcss-sass': 'node-commonjs postcss-sass',
'postcss-styl': 'node-commonjs postcss-styl',
sugarss: 'node-commonjs sugarss',
'stylelint-scss/src/rules/dollar-variable-empty-line-before/index.js':
'node-commonjs stylelint-scss/src/rules/dollar-variable-empty-line-before/index.js',
'stylelint-scss/src/rules/double-slash-comment-empty-line-before/index.js':
'node-commonjs stylelint-scss/src/rules/double-slash-comment-empty-line-before/index.js',
},
],
externalsType: 'module-import',
chain(chain) {
// chain.plugin('rsdoctor').use(RsdoctorWebpackPlugin, [
// {
// port: 5858,
// },
// ]);
},
};
1 change: 1 addition & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from '@nice-move/eslint-config-base';
278 changes: 187 additions & 91 deletions lib/handle-script/options.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import html from '@nice-move/eslint-plugin-html/lib/configs.cjs';
import { base as html } from '@nice-move/eslint-plugin-html/lib/configs-next.mjs';
import stylisticJs from '@stylistic/eslint-plugin-js';
import stylisticJsx from '@stylistic/eslint-plugin-jsx';
import stylisticTs from '@stylistic/eslint-plugin-ts';
import tsParser from '@typescript-eslint/parser';
import sortClassMembers from 'eslint-plugin-sort-class-members';

import { pluginMap, plugins, rules } from './plugins.mjs';
import vueParser from 'vue-eslint-parser';

import { pluginMap, rules } from './plugins.mjs';
import { rules as react } from './react.mjs';
import { rules as vue } from './vue.mjs';

Expand All @@ -17,24 +24,91 @@ const always = [

const never = ['break', 'case', 'default', 'continue', 'debugger', 'switch'];

const [html1, html2] = html.base.overrides;
const padding = [
'warn',
{
blankLine: 'always',
prev: '*',
next: always,
},
{
blankLine: 'always',
prev: ['directive', 'import', ...always],
next: '*',
},
{
blankLine: 'never',
prev: '*',
next: never,
},
{
blankLine: 'never',
prev: never,
next: '*',
},
{
blankLine: 'any',
prev: 'import',
next: 'import',
},
{
blankLine: 'never',
prev: 'cjs-import',
next: 'cjs-import',
},
];

const comment = [
'warn',
'always',
{
block: {
balanced: true,
exceptions: ['-', '+', '/', '*'],
markers: ['=', '!', ':', '::', '/', '*'],
},
line: {
exceptions: ['-', '+', '/', '*'],
markers: ['=', '!', '/', '*'],
},
},
];

const quotes = [
'warn',
'single',
{
avoidEscape: true,
allowTemplateLiterals: false,
},
];

const props = [
'warn',
{
callbacksLast: false,
shorthandFirst: false,
shorthandLast: false,
ignoreCase: false,
noSortAlphabetically: false,
reservedFirst: true,
},
];

const baseConfig = {
parserOptions: {
files: ['**/*.{js,jsx,ts,tsx,mjs,mts,cjs,cts,qs,wxs,vue}'],
languageOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
parserOptions: {
ecmaFeatures: {
impliedStrict: true,
globalReturn: true,
},
},
},
plugins,
rules: {
curly: ['warn', 'all'],
quotes: [
'warn',
'single',
{
avoidEscape: true,
allowTemplateLiterals: false,
},
],
'no-useless-rename': 'warn',
'prefer-exponentiation-operator': 'warn',
'prefer-template': 'warn',
Expand All @@ -45,108 +119,130 @@ const baseConfig = {
avoidQuotes: true,
},
],
'padding-line-between-statements': [
'sort-class-members/sort-class-members': [
'warn',
{
blankLine: 'always',
prev: '*',
next: always,
},
{
blankLine: 'always',
prev: ['directive', 'import', ...always],
next: '*',
},
{
blankLine: 'never',
prev: '*',
next: never,
},
{
blankLine: 'never',
prev: never,
next: '*',
},
{
blankLine: 'any',
prev: 'import',
next: 'import',
},
{
blankLine: 'never',
prev: 'cjs-import',
next: 'cjs-import',
},
],
'lines-between-class-members': 'warn',
'spaced-comment': [
'warn',
'always',
{
block: {
balanced: true,
exceptions: ['-', '+', '/', '*'],
markers: ['=', '!', ':', '::', '/', '*'],
},
line: {
exceptions: ['-', '+', '/', '*'],
markers: ['=', '!', '/', '*'],
},
accessorPairPositioning: 'getThenSet',
order: [
'[static-properties]',
'[static-methods]',
'[properties]',
'[conventional-private-properties]',
'constructor',
'componentWillMount',
'componentDidMount',
'componentWillReceiveProps',
'shouldComponentUpdate',
'componentWillUpdate',
'componentDidUpdate',
'componentWillUnmount',
'[arrow-function-properties]',
'[methods]',
'[conventional-private-methods]',
'render',
],
},
],
...rules,
},
overrides: [
{ files: ['*.cjs', '*.mjs'] },
plugins: pluginMap,
};

export const options = {
allowInlineConfig: false,
errorOnUnmatchedPattern: false,
fix: true,
globInputPaths: false,
overrideConfigFile: true,
baseConfig: [
sortClassMembers.configs['flat/recommended'],
...html,
baseConfig,
{
files: ['*.html', '*.htm'],
processor: 'garou/html',
files: ['**/*.md'],
processor: 'garou/markdown',
plugins: pluginMap,
},
html1,
html2,
{
files: [...html1.files, ...html2.files],
rules: {
'garou/import-first': 0,
files: ['**/*.md/**'],
languageOptions: {
ecmaVersion: 'latest',
},
},
{
files: ['*.md'],
processor: 'garou/markdown',
},
{
files: ['*.ts', '*.tsx', '*.cts', '*.mts'],
parser: '@typescript-eslint/parser',
files: ['**/*.ts', '**/*.tsx', '**/*.cts', '**/*.mts'],
languageOptions: {
parser: tsParser,
},
rules: {
'garou/consistent-type-specifier-style': ['warn', 'prefer-top-level'],
},
},
{
files: ['*.jsx', '*.tsx'],
parserOptions: {
ecmaFeatures: {
jsx: true,
files: ['**/*.jsx', '**/*.tsx'],
languageOptions: {
parserOptions: {
ecmaFeatures: {
jsx: true,
},
},
},
rules: react,
},
{
files: '*.vue',
parserOptions: {
ecmaVersion: 2022,
files: ['**/*.vue'],
languageOptions: {
ecmaVersion: 'latest',
parser: vueParser,
},
parser: 'vue-eslint-parser',
rules: vue,
},
{
files: [
'**/*.cjs',
'**/*.js',
'**/*.jsx',
'**/*.mjs',
'**/*.qs',
'**/*.vue',
'**/*.wxs',
],
plugins: {
'@stylistic/js': stylisticJs,
},
rules: {
'@stylistic/js/lines-between-class-members': 'warn',
'@stylistic/js/padding-line-between-statements': padding,
'@stylistic/js/quotes': quotes,
'@stylistic/js/spaced-comment': comment,
},
},
{
files: ['**/*.ts', '**/*.mts', '**/*.cts', '**/*.tsx'],
plugins: {
'@stylistic/ts': stylisticTs,
'@stylistic/js': stylisticJs,
},
rules: {
'@stylistic/js/quotes': quotes,
'@stylistic/js/spaced-comment': comment,
'@stylistic/ts/lines-between-class-members': 'warn',
'@stylistic/ts/padding-line-between-statements': padding,
},
},
{
files: ['**/*.jsx', '**/*.tsx'],
plugins: {
'@stylistic/jsx': stylisticJsx,
},
rules: {
'@stylistic/jsx/jsx-sort-props': props,
'@stylistic/jsx/jsx-self-closing-comp': 'warn',
'@stylistic/jsx/jsx-curly-brace-presence': [
'warn',
{ props: 'never', children: 'ignore' },
],
},
},
],
};

export const options = {
allowInlineConfig: false,
baseConfig,
errorOnUnmatchedPattern: false,
fix: true,
globInputPaths: false,
plugins: pluginMap,
useEslintrc: false,
};
Loading

0 comments on commit de61e7a

Please sign in to comment.