From 3329fdf2cef710ba92b1f4e98132cc79091e0cbe 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 | 64 +++++++++++++++++---------------------- .prettierignore | 2 +- .prettierrc.js | 4 +-- babel.config.js | 74 +++++++++++++++++++++------------------------ ide-helper.js | 2 +- stylelint.config.js | 7 ++--- 6 files changed, 70 insertions(+), 83 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 502b9cefed..b118543bde 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -52,10 +52,7 @@ module.exports = defineConfig({ react: { version: 'detect', }, - 'import/ignore': [ - 'node_modules', - '\\.(css|scss|json)$', - ], + 'import/ignore': ['node_modules', '\\.(css|scss|json)$'], 'import/resolver': { typescript: {}, }, @@ -64,19 +61,16 @@ 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': 'off', @@ -150,9 +144,7 @@ module.exports = defineConfig({ 'jsx-a11y/no-noninteractive-element-interactions': [ 'warn', { - handlers: [ - 'onClick', - ], + handlers: ['onClick'], }, ], // recommended rule is: @@ -170,9 +162,7 @@ module.exports = defineConfig({ 'jsx-a11y/no-static-element-interactions': [ 'warn', { - handlers: [ - 'onClick', - ], + handlers: ['onClick'], }, ], @@ -245,7 +235,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', }, @@ -322,10 +313,7 @@ module.exports = defineConfig({ }, }, { - files: [ - '**/*.ts', - '**/*.tsx', - ], + files: ['**/*.ts', '**/*.tsx'], extends: [ 'eslint:recommended', @@ -347,21 +335,25 @@ module.exports = defineConfig({ rules: { // Disable formatting rules that have been enabled in the base config - 'indent': 'off', + indent: 'off', 'import/consistent-type-specifier-style': ['error', 'prefer-top-level'], '@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", + '@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." - } + name: 'react-redux', + importNames: ['useSelector', 'useDispatch'], + message: + 'Use typed hooks `useAppDispatch` and `useAppSelector` instead.', + }, ], 'jsdoc/require-jsdoc': 'off', @@ -369,21 +361,21 @@ module.exports = defineConfig({ // 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 6b2f0c1889..fdc1dccc8a 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 af39b253f6..94eaee9ae8 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 9ced748a96..84e2b3c1d2 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/, - presets: [ - ['@babel/env', { ...envOptions, modules: 'commonjs' }], - ], + presets: [['@babel/env', { ...envOptions, modules: 'commonjs' }]], }, ], }; diff --git a/ide-helper.js b/ide-helper.js index 9e645cb0eb..12d8f01882 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 9f95091630..5f39c371d7 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-/'], + }, ], }, },