mirror of
https://github.com/mastodon/mastodon.git
synced 2024-08-20 21:08:15 -07:00
Opt-in root javascript files to Prettier
This commit is contained in:
parent
06f070d86d
commit
5960b552fa
6 changed files with 75 additions and 83 deletions
69
.eslintrc.js
69
.eslintrc.js
|
@ -48,10 +48,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: {},
|
||||||
},
|
},
|
||||||
|
@ -60,22 +57,19 @@ 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': ['error', { "allowEmptyCatch": true }],
|
'no-empty': ['error', { allowEmptyCatch: true }],
|
||||||
'no-restricted-properties': [
|
'no-restricted-properties': [
|
||||||
'error',
|
'error',
|
||||||
{ property: 'substring', message: 'Use .slice instead of .substring.' },
|
{ property: 'substring', message: 'Use .slice instead of .substring.' },
|
||||||
|
@ -145,9 +139,7 @@ module.exports = defineConfig({
|
||||||
'jsx-a11y/no-static-element-interactions': [
|
'jsx-a11y/no-static-element-interactions': [
|
||||||
'warn',
|
'warn',
|
||||||
{
|
{
|
||||||
handlers: [
|
handlers: ['onClick'],
|
||||||
'onClick',
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
||||||
|
@ -220,7 +212,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',
|
||||||
},
|
},
|
||||||
|
@ -297,10 +290,7 @@ module.exports = defineConfig({
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
files: [
|
files: ['**/*.ts', '**/*.tsx'],
|
||||||
'**/*.ts',
|
|
||||||
'**/*.tsx',
|
|
||||||
],
|
|
||||||
|
|
||||||
extends: [
|
extends: [
|
||||||
'eslint:recommended',
|
'eslint:recommended',
|
||||||
|
@ -322,7 +312,7 @@ 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',
|
||||||
|
|
||||||
// This is not needed as we use noImplicitReturns, which handles this in addition to understanding types
|
// This is not needed as we use noImplicitReturns, which handles this in addition to understanding types
|
||||||
'consistent-return': 'off',
|
'consistent-return': 'off',
|
||||||
|
@ -332,37 +322,44 @@ module.exports = defineConfig({
|
||||||
'@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 } },
|
||||||
{
|
],
|
||||||
"name": "react-redux",
|
'@typescript-eslint/no-restricted-imports': [
|
||||||
"importNames": ["useSelector", "useDispatch"],
|
'warn',
|
||||||
"message": "Use typed hooks `useAppDispatch` and `useAppSelector` instead."
|
{
|
||||||
}
|
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',
|
'jsdoc/require-jsdoc': 'off',
|
||||||
|
|
||||||
// Those rules set stricter rules for TS files
|
// Those rules set stricter rules for TS files
|
||||||
// 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,
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
module.exports = {
|
module.exports = {
|
||||||
singleQuote: true,
|
singleQuote: true,
|
||||||
jsxSingleQuote: true
|
jsxSingleQuote: true,
|
||||||
}
|
};
|
||||||
|
|
|
@ -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/, /fuzzysort\.js/],
|
test: [/tesseract\.js/, /fuzzysort\.js/],
|
||||||
presets: [
|
presets: [['@babel/env', { ...envOptions, modules: 'commonjs' }]],
|
||||||
['@babel/env', { ...envOptions, modules: 'commonjs' }],
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
|
@ -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'),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -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-/',
|
},
|
||||||
] },
|
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue