Opt-in root javascript files to Prettier

This commit is contained in:
Nick Schonning 2024-02-28 17:17:29 -05:00
parent be52633ee4
commit 3329fdf2ce
No known key found for this signature in database
GPG Key ID: 5DDAAD9C9AAFFD9F
6 changed files with 70 additions and 83 deletions

View File

@ -52,10 +52,7 @@ module.exports = defineConfig({
react: { react: {
version: 'detect', version: 'detect',
}, },
'import/ignore': [ 'import/ignore': ['node_modules', '\\.(css|scss|json)$'],
'node_modules',
'\\.(css|scss|json)$',
],
'import/resolver': { 'import/resolver': {
typescript: {}, typescript: {},
}, },
@ -64,19 +61,16 @@ module.exports = defineConfig({
rules: { rules: {
'consistent-return': 'error', 'consistent-return': 'error',
'dot-notation': 'error', 'dot-notation': 'error',
eqeqeq: ['error', 'always', { 'null': 'ignore' }], eqeqeq: ['error', 'always', { null: 'ignore' }],
'indent': ['error', 2], indent: ['error', 2],
'jsx-quotes': ['error', 'prefer-single'], 'jsx-quotes': ['error', 'prefer-single'],
'semi': ['error', 'always'], semi: ['error', 'always'],
'no-case-declarations': 'off', 'no-case-declarations': 'off',
'no-catch-shadow': 'error', 'no-catch-shadow': 'error',
'no-console': [ 'no-console': [
'warn', 'warn',
{ {
allow: [ allow: ['error', 'warn'],
'error',
'warn',
],
}, },
], ],
'no-empty': 'off', 'no-empty': 'off',
@ -150,9 +144,7 @@ module.exports = defineConfig({
'jsx-a11y/no-noninteractive-element-interactions': [ 'jsx-a11y/no-noninteractive-element-interactions': [
'warn', 'warn',
{ {
handlers: [ handlers: ['onClick'],
'onClick',
],
}, },
], ],
// recommended rule is: // recommended rule is:
@ -170,9 +162,7 @@ module.exports = defineConfig({
'jsx-a11y/no-static-element-interactions': [ 'jsx-a11y/no-static-element-interactions': [
'warn', 'warn',
{ {
handlers: [ handlers: ['onClick'],
'onClick',
],
}, },
], ],
@ -245,7 +235,8 @@ module.exports = defineConfig({
}, },
// Immutable / Redux / data store // Immutable / Redux / data store
{ {
pattern: '{immutable,@reduxjs/toolkit,react-redux,react-immutable-proptypes,react-immutable-pure-component}', pattern:
'{immutable,@reduxjs/toolkit,react-redux,react-immutable-proptypes,react-immutable-pure-component}',
group: 'external', group: 'external',
position: 'before', position: 'before',
}, },
@ -322,10 +313,7 @@ module.exports = defineConfig({
}, },
}, },
{ {
files: [ files: ['**/*.ts', '**/*.tsx'],
'**/*.ts',
'**/*.tsx',
],
extends: [ extends: [
'eslint:recommended', 'eslint:recommended',
@ -347,21 +335,25 @@ module.exports = defineConfig({
rules: { rules: {
// Disable formatting rules that have been enabled in the base config // Disable formatting rules that have been enabled in the base config
'indent': 'off', indent: 'off',
'import/consistent-type-specifier-style': ['error', 'prefer-top-level'], 'import/consistent-type-specifier-style': ['error', 'prefer-top-level'],
'@typescript-eslint/consistent-type-definitions': ['warn', 'interface'], '@typescript-eslint/consistent-type-definitions': ['warn', 'interface'],
'@typescript-eslint/consistent-type-exports': 'error', '@typescript-eslint/consistent-type-exports': 'error',
'@typescript-eslint/consistent-type-imports': 'error', '@typescript-eslint/consistent-type-imports': 'error',
"@typescript-eslint/prefer-nullish-coalescing": ['error', { ignorePrimitives: { boolean: true } }], '@typescript-eslint/prefer-nullish-coalescing': [
"@typescript-eslint/no-restricted-imports": [ 'error',
"warn", { ignorePrimitives: { boolean: true } },
],
'@typescript-eslint/no-restricted-imports': [
'warn',
{ {
"name": "react-redux", name: 'react-redux',
"importNames": ["useSelector", "useDispatch"], importNames: ['useSelector', 'useDispatch'],
"message": "Use typed hooks `useAppDispatch` and `useAppSelector` instead." message:
} 'Use typed hooks `useAppDispatch` and `useAppSelector` instead.',
},
], ],
'jsdoc/require-jsdoc': 'off', 'jsdoc/require-jsdoc': 'off',
@ -369,21 +361,21 @@ module.exports = defineConfig({
// to enforce better practices when converting from JS // to enforce better practices when converting from JS
'import/no-default-export': 'warn', 'import/no-default-export': 'warn',
'react/prefer-stateless-function': 'warn', 'react/prefer-stateless-function': 'warn',
'react/function-component-definition': ['error', { namedComponents: 'arrow-function' }], 'react/function-component-definition': [
'error',
{ namedComponents: 'arrow-function' },
],
'react/jsx-uses-react': 'off', // not needed with new JSX transform 'react/jsx-uses-react': 'off', // not needed with new JSX transform
'react/react-in-jsx-scope': 'off', // not needed with new JSX transform 'react/react-in-jsx-scope': 'off', // not needed with new JSX transform
'react/prop-types': 'off', 'react/prop-types': 'off',
}, },
}, },
{ {
files: [ files: ['**/__tests__/*.js', '**/__tests__/*.jsx'],
'**/__tests__/*.js',
'**/__tests__/*.jsx',
],
env: { env: {
jest: true, jest: true,
}, },
} },
], ],
}); });

View File

@ -82,4 +82,4 @@ app/javascript/styles/mastodon/reset.scss
AUTHORS.md AUTHORS.md
# Process a few selected JS files # Process a few selected JS files
!lint-staged.config.js !/*.js

View File

@ -1,4 +1,4 @@
module.exports = { module.exports = {
singleQuote: true, singleQuote: true,
jsxSingleQuote: true jsxSingleQuote: true,
} };

View File

@ -1,3 +1,4 @@
/* eslint-disable indent */
module.exports = (api) => { module.exports = (api) => {
const env = api.env(); const env = api.env();
@ -7,8 +8,8 @@ module.exports = (api) => {
}; };
const envOptions = { const envOptions = {
useBuiltIns: "usage", useBuiltIns: 'usage',
corejs: { version: "3.30" }, corejs: { version: '3.30' },
debug: false, debug: false,
include: [ include: [
'transform-numeric-separator', 'transform-numeric-separator',
@ -18,45 +19,42 @@ module.exports = (api) => {
], ],
}; };
const plugins = [ const plugins = [['formatjs'], 'preval'];
['formatjs'],
'preval',
];
switch (env) { switch (env) {
case 'production': case 'production':
plugins.push(...[ plugins.push(
'lodash', ...[
[ 'lodash',
'transform-react-remove-prop-types', [
{ 'transform-react-remove-prop-types',
mode: 'remove', {
removeImport: true, mode: 'remove',
additionalLibraries: [ removeImport: true,
'react-immutable-proptypes', additionalLibraries: ['react-immutable-proptypes'],
},
], ],
}, '@babel/transform-react-inline-elements',
], [
'@babel/transform-react-inline-elements', '@babel/transform-runtime',
[ {
'@babel/transform-runtime', helpers: true,
{ regenerator: false,
helpers: true, useESModules: true,
regenerator: false, },
useESModules: true, ],
}, ],
], );
]); break;
break;
case 'development': case 'development':
reactOptions.development = true; reactOptions.development = true;
envOptions.debug = true; envOptions.debug = true;
// We need Babel to not inject polyfills in dev, as this breaks `preval` files // We need Babel to not inject polyfills in dev, as this breaks `preval` files
envOptions.useBuiltIns = false; envOptions.useBuiltIns = false;
envOptions.corejs = undefined; envOptions.corejs = undefined;
break; break;
} }
const config = { const config = {
@ -69,9 +67,7 @@ module.exports = (api) => {
overrides: [ overrides: [
{ {
test: /tesseract\.js/, test: /tesseract\.js/,
presets: [ presets: [['@babel/env', { ...envOptions, modules: 'commonjs' }]],
['@babel/env', { ...envOptions, modules: 'commonjs' }],
],
}, },
], ],
}; };

View File

@ -6,7 +6,7 @@ jetbrains://WebStorm/settings?name=Languages+%26+Frameworks--JavaScript--Webpack
module.exports = { module.exports = {
resolve: { resolve: {
alias: { alias: {
'mastodon': path.resolve(__dirname, 'app/javascript/mastodon'), mastodon: path.resolve(__dirname, 'app/javascript/mastodon'),
}, },
}, },
}; };

View File

@ -31,14 +31,13 @@ module.exports = {
}, },
overrides: [ overrides: [
{ {
'files': ['app/javascript/styles/mailer.scss'], files: ['app/javascript/styles/mailer.scss'],
rules: { rules: {
'property-no-unknown': [ 'property-no-unknown': [
true, true,
{ {
ignoreProperties: [ ignoreProperties: ['/^mso-/'],
'/^mso-/', },
] },
], ],
}, },
}, },