From 5960b552fa35afb0fed19dd742ed49cf6a48ad69 Mon Sep 17 00:00:00 2001 From: Nick Schonning Date: Wed, 28 Feb 2024 17:17:29 -0500 Subject: [PATCH] Opt-in root javascript files to Prettier --- .eslintrc.js | 69 ++++++++++++++++++++---------------------- .prettierignore | 2 +- .prettierrc.js | 4 +-- babel.config.js | 74 +++++++++++++++++++++------------------------ ide-helper.js | 2 +- stylelint.config.js | 7 ++--- 6 files changed, 75 insertions(+), 83 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index d1182628263..9237e9866c5 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -48,10 +48,7 @@ module.exports = defineConfig({ react: { version: 'detect', }, - 'import/ignore': [ - 'node_modules', - '\\.(css|scss|json)$', - ], + 'import/ignore': ['node_modules', '\\.(css|scss|json)$'], 'import/resolver': { typescript: {}, }, @@ -60,22 +57,19 @@ module.exports = defineConfig({ rules: { 'consistent-return': 'error', 'dot-notation': 'error', - eqeqeq: ['error', 'always', { 'null': 'ignore' }], - 'indent': ['error', 2], + eqeqeq: ['error', 'always', { null: 'ignore' }], + indent: ['error', 2], 'jsx-quotes': ['error', 'prefer-single'], - 'semi': ['error', 'always'], + semi: ['error', 'always'], 'no-case-declarations': 'off', 'no-catch-shadow': 'error', 'no-console': [ 'warn', { - allow: [ - 'error', - 'warn', - ], + allow: ['error', 'warn'], }, ], - 'no-empty': ['error', { "allowEmptyCatch": true }], + 'no-empty': ['error', { allowEmptyCatch: true }], 'no-restricted-properties': [ 'error', { property: 'substring', message: 'Use .slice instead of .substring.' }, @@ -145,9 +139,7 @@ module.exports = defineConfig({ 'jsx-a11y/no-static-element-interactions': [ 'warn', { - handlers: [ - 'onClick', - ], + handlers: ['onClick'], }, ], @@ -220,7 +212,8 @@ module.exports = defineConfig({ }, // 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', position: 'before', }, @@ -297,10 +290,7 @@ module.exports = defineConfig({ }, }, { - files: [ - '**/*.ts', - '**/*.tsx', - ], + files: ['**/*.ts', '**/*.tsx'], extends: [ 'eslint:recommended', @@ -322,7 +312,7 @@ module.exports = defineConfig({ rules: { // Disable formatting rules that have been enabled in the base config - 'indent': 'off', + indent: 'off', // This is not needed as we use noImplicitReturns, which handles this in addition to understanding types 'consistent-return': 'off', @@ -332,37 +322,44 @@ module.exports = defineConfig({ '@typescript-eslint/consistent-type-definitions': ['warn', 'interface'], '@typescript-eslint/consistent-type-exports': 'error', '@typescript-eslint/consistent-type-imports': 'error', - "@typescript-eslint/prefer-nullish-coalescing": ['error', { ignorePrimitives: { boolean: true } }], - "@typescript-eslint/no-restricted-imports": [ - "warn", - { - "name": "react-redux", - "importNames": ["useSelector", "useDispatch"], - "message": "Use typed hooks `useAppDispatch` and `useAppSelector` instead." - } + '@typescript-eslint/prefer-nullish-coalescing': [ + 'error', + { ignorePrimitives: { boolean: true } }, + ], + '@typescript-eslint/no-restricted-imports': [ + 'warn', + { + name: 'react-redux', + importNames: ['useSelector', 'useDispatch'], + message: + 'Use typed hooks `useAppDispatch` and `useAppSelector` instead.', + }, + ], + '@typescript-eslint/restrict-template-expressions': [ + 'warn', + { allowNumber: true }, ], - "@typescript-eslint/restrict-template-expressions": ['warn', { allowNumber: true }], 'jsdoc/require-jsdoc': 'off', // Those rules set stricter rules for TS files // to enforce better practices when converting from JS 'import/no-default-export': '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/react-in-jsx-scope': 'off', // not needed with new JSX transform 'react/prop-types': 'off', }, }, { - files: [ - '**/__tests__/*.js', - '**/__tests__/*.jsx', - ], + files: ['**/__tests__/*.js', '**/__tests__/*.jsx'], env: { jest: true, }, - } + }, ], }); diff --git a/.prettierignore b/.prettierignore index 6b2f0c18894..fdc1dccc8ad 100644 --- a/.prettierignore +++ b/.prettierignore @@ -82,4 +82,4 @@ app/javascript/styles/mastodon/reset.scss AUTHORS.md # Process a few selected JS files -!lint-staged.config.js +!/*.js diff --git a/.prettierrc.js b/.prettierrc.js index af39b253f60..94eaee9ae81 100644 --- a/.prettierrc.js +++ b/.prettierrc.js @@ -1,4 +1,4 @@ module.exports = { singleQuote: true, - jsxSingleQuote: true -} + jsxSingleQuote: true, +}; diff --git a/babel.config.js b/babel.config.js index 4c2fe5682bb..b46c7034719 100644 --- a/babel.config.js +++ b/babel.config.js @@ -1,3 +1,4 @@ +/* eslint-disable indent */ module.exports = (api) => { const env = api.env(); @@ -7,8 +8,8 @@ module.exports = (api) => { }; const envOptions = { - useBuiltIns: "usage", - corejs: { version: "3.30" }, + useBuiltIns: 'usage', + corejs: { version: '3.30' }, debug: false, include: [ 'transform-numeric-separator', @@ -18,45 +19,42 @@ module.exports = (api) => { ], }; - const plugins = [ - ['formatjs'], - 'preval', - ]; + const plugins = [['formatjs'], 'preval']; switch (env) { - case 'production': - plugins.push(...[ - 'lodash', - [ - 'transform-react-remove-prop-types', - { - mode: 'remove', - removeImport: true, - additionalLibraries: [ - 'react-immutable-proptypes', + case 'production': + plugins.push( + ...[ + 'lodash', + [ + 'transform-react-remove-prop-types', + { + mode: 'remove', + removeImport: true, + additionalLibraries: ['react-immutable-proptypes'], + }, ], - }, - ], - '@babel/transform-react-inline-elements', - [ - '@babel/transform-runtime', - { - helpers: true, - regenerator: false, - useESModules: true, - }, - ], - ]); - break; + '@babel/transform-react-inline-elements', + [ + '@babel/transform-runtime', + { + helpers: true, + regenerator: false, + useESModules: true, + }, + ], + ], + ); + break; - case 'development': - reactOptions.development = true; - envOptions.debug = true; + case 'development': + reactOptions.development = true; + envOptions.debug = true; - // We need Babel to not inject polyfills in dev, as this breaks `preval` files - envOptions.useBuiltIns = false; - envOptions.corejs = undefined; - break; + // We need Babel to not inject polyfills in dev, as this breaks `preval` files + envOptions.useBuiltIns = false; + envOptions.corejs = undefined; + break; } const config = { @@ -69,9 +67,7 @@ module.exports = (api) => { overrides: [ { test: [/tesseract\.js/, /fuzzysort\.js/], - presets: [ - ['@babel/env', { ...envOptions, modules: 'commonjs' }], - ], + presets: [['@babel/env', { ...envOptions, modules: 'commonjs' }]], }, ], }; diff --git a/ide-helper.js b/ide-helper.js index 9e645cb0ebe..12d8f01882d 100644 --- a/ide-helper.js +++ b/ide-helper.js @@ -6,7 +6,7 @@ jetbrains://WebStorm/settings?name=Languages+%26+Frameworks--JavaScript--Webpack module.exports = { resolve: { alias: { - 'mastodon': path.resolve(__dirname, 'app/javascript/mastodon'), + mastodon: path.resolve(__dirname, 'app/javascript/mastodon'), }, }, }; diff --git a/stylelint.config.js b/stylelint.config.js index 9f95091630a..5f39c371d7b 100644 --- a/stylelint.config.js +++ b/stylelint.config.js @@ -31,14 +31,13 @@ module.exports = { }, overrides: [ { - 'files': ['app/javascript/styles/mailer.scss'], + files: ['app/javascript/styles/mailer.scss'], rules: { 'property-no-unknown': [ true, { - ignoreProperties: [ - '/^mso-/', - ] }, + ignoreProperties: ['/^mso-/'], + }, ], }, },