Skip to content

Commit

Permalink
build: modernize tooling
Browse files Browse the repository at this point in the history
  • Loading branch information
Xunnamius committed Nov 2, 2023
1 parent d92ec30 commit db0223e
Show file tree
Hide file tree
Showing 13 changed files with 17,885 additions and 11,976 deletions.
227 changes: 145 additions & 82 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,80 +1,151 @@
'use strict';

const debug = require('debug')(`${require('./package.json').name}:eslint-config`);
const restrictedGlobals = require('confusing-browser-globals');
const plugins = ['unicorn', '@typescript-eslint', 'import'];

const xtends = [
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'plugin:import/errors',
'plugin:import/warnings',
'plugin:import/typescript',
'plugin:unicorn/recommended'
];

const environment = {
es2022: true,
node: true
// * Instead of including more options here, enable them on a per-file basis
};

const rules = {
'no-console': 'warn',
'no-return-await': 'warn',
'no-await-in-loop': 'warn',
'import/no-unresolved': ['error', { commonjs: true }],
'no-extra-boolean-cast': 'off',
'no-empty': 'off',
'@typescript-eslint/camelcase': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/prefer-ts-expect-error': 'warn',
'@typescript-eslint/no-floating-promises': ['error', { ignoreVoid: true }],
'@typescript-eslint/ban-ts-comment': [
'warn',
{
'ts-expect-error': 'allow-with-description',
minimumDescriptionLength: 6
}
],
'@typescript-eslint/no-unused-vars': [
'warn',
{
argsIgnorePattern: '^_+',
varsIgnorePattern: '^_+',
caughtErrorsIgnorePattern: '^ignored?\\d*$',
caughtErrors: 'all'
}
],
// ? Ever since v4, we will rely on TypeScript to catch these
'no-undef': 'off',
'@typescript-eslint/no-var-requires': 'off',
// ? I'll be good, I promise
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/consistent-type-imports': [
'error',
{ disallowTypeAnnotations: false, fixStyle: 'inline-type-imports' }
],
'@typescript-eslint/consistent-type-exports': [
'error',
{ fixMixedExportsWithInlineTypeSpecifier: true }
],
'no-unused-vars': 'off',
'unicorn/no-keyword-prefix': 'warn',
'unicorn/prefer-string-replace-all': 'warn',
// ? Handled by integration tests
'unicorn/prefer-module': 'off',
// ? I am of the opinion that there is a difference between something being
// ? defined as nothing and something being undefined
'unicorn/no-null': 'off',
// ? If MongoDB can get away with "DB" in its name, so can we. Also,
// ? unnecessary underscores are a big no-no.
'unicorn/prevent-abbreviations': [
'warn',
{
checkFilenames: false,
replacements: {
args: false,
str: false,
fn: false,
db: false,
dir: false,
dist: false,
tmp: false,
pkg: false,
src: false,
dest: false,
obj: false,
val: false,
env: false,
temp: false,
req: false,
res: false
},
ignore: [/stderr/i]
}
],
// ? Actually, I rather like this curt syntax
'unicorn/no-await-expression-member': 'off',
// ? Between disabling this and disabling no-empty-function, I choose this
'unicorn/no-useless-undefined': 'off',
// ? Not sure why this isn't the default
'unicorn/prefer-export-from': ['warn', { ignoreUsedVariables: true }],
// ? Yeah, I read The Good Parts too, I know what I'm doing
'unicorn/consistent-function-scoping': 'off',
// ? It's 2022. Use Prettier
'unicorn/no-nested-ternary': 'off',
// ? `Array.from` communicates intent much better than `[...]`
'unicorn/prefer-spread': 'off',
// ? Not realistic when using TypeScript
'unicorn/prefer-native-coercion-functions': 'off',
// ? Premature optimization is evil
'unicorn/no-array-for-each': 'off',
// ? Lol, no
'unicorn/explicit-length-check': 'off',
// ? I don't think so
'unicorn/no-negated-condition': 'off',
// ? This is not it, chief (Prettier prevails)
'unicorn/number-literal-case': 'off',
// ? I'll decide when I want switch cases for fallthrough or not, thanks
'unicorn/prefer-switch': 'off',
// ? No, thanks
'unicorn/prefer-set-has': 'off'
};

module.exports = {
parser: '@typescript-eslint/parser',
plugins: ['jest', '@typescript-eslint', 'import'],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'plugin:import/errors',
'plugin:import/warnings',
'plugin:import/typescript'
],
plugins,
extends: xtends,
parserOptions: {
ecmaVersion: 8,
ecmaVersion: 'latest',
sourceType: 'module',
ecmaFeatures: {
impliedStrict: true,
experimentalObjectRestSpread: true,
jsx: true
},
extraFileExtensions: ['.mjs', '.cjs'],
project: 'tsconfig.eslint.json'
},
env: {
es6: true,
node: true,
jest: true,
'jest/globals': true,
browser: true,
webextensions: true
},
rules: {
'no-console': 'warn',
'no-return-await': 'warn',
'no-await-in-loop': 'warn',
'import/no-unresolved': ['error', { commonjs: true }],
'no-restricted-globals': ['warn'].concat(restrictedGlobals),
'no-extra-boolean-cast': 'off',
'no-empty': 'off',
'@typescript-eslint/camelcase': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/prefer-ts-expect-error': 'warn',
'@typescript-eslint/no-floating-promises': [
'error',
{ ignoreVoid: true, ignoreIIFE: true }
],
'@typescript-eslint/ban-ts-comment': [
'warn',
{
'ts-expect-error': 'allow-with-description',
minimumDescriptionLength: 6
}
],
'@typescript-eslint/no-unused-vars': [
'warn',
{
argsIgnorePattern: '^_+',
varsIgnorePattern: '^_+',
caughtErrorsIgnorePattern: '^ignored?\\d*$',
caughtErrors: 'all'
}
],
// ? Ever since v4, we will rely on TypeScript to catch these
'no-undef': 'off',
'@typescript-eslint/no-var-requires': 'off',
'no-unused-vars': 'off'
},
env: environment,
rules,
overrides: [
{
files: ['*.test.*'],
extends: ['plugin:jest/all', 'plugin:jest/style'],
plugins: [...plugins, 'jest'],
env: { ...environment, jest: true },
extends: [...xtends, 'plugin:jest/all', 'plugin:jest/style'],
rules: {
...rules,
'jest/lowercase': 'off',
'jest/consistent-test-it': 'off',
'jest/require-top-level-describe': 'off',
Expand All @@ -89,7 +160,10 @@ module.exports = {
'jest/no-alias-methods': 'off',
'jest/max-expects': 'off',
'jest/prefer-mock-promise-shorthand': 'off',
'jest/prefer-each': 'off'
'jest/no-conditional-in-test': 'off',
'jest/no-conditional-expect': 'off',
'jest/prefer-each': 'off',
'jest/prefer-snapshot-hint': 'off'
}
}
],
Expand All @@ -100,23 +174,11 @@ module.exports = {
'import/extensions': ['.ts', '.tsx', '.js', '.jsx'],
// ? Switch parsers depending on which type of file we're looking at
'import/parsers': {
'@typescript-eslint/parser': ['.ts', '.tsx'],
'@babel/eslint-parser': ['.js', '.jsx']
'@typescript-eslint/parser': ['.ts', '.tsx', '.cts', '.mts'],
'@babel/eslint-parser': ['.js', '.jsx', '.cjs', '.mjs']
},
'import/resolver': {
alias: {
map: [
// ! If changed, also update these aliases in tsconfig.json,
// ! webpack.config.js, next.config.ts, and jest.config.js
['universe', './src'],
['multiverse', './lib'],
['testverse', './test'],
['externals', './external-scripts'],
['types', './types'],
['package', './package.json']
],
extensions: ['.js', '.jsx', '.ts', '.tsx']
},
node: {},
typescript: {}
},
'import/ignore': [
Expand All @@ -125,13 +187,14 @@ module.exports = {
'.*/bin/.*'
]
},
ignorePatterns: ['coverage', 'dist', 'bin', 'build', '/next.config.js'],
globals: {
page: true,
browser: true,
context: true,
jestPuppeteer: true
}
ignorePatterns: [
'coverage',
'dist',
'fixtures',
'__fixtures__',
'__snapshots__',
'test/integration/assets'
]
};

debug('exports: %O', module.exports);
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ ignore.*
dist
build
.vscode
!.vscode/launch.example.json
.vercel
.env
.npmrc
external-scripts/bin
next-env.d.ts
node_modules
coverage
.DS_Store
4 changes: 2 additions & 2 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh
. "$(dirname $0)/_/husky.sh"

if [ -z $GAC_VERIFY_SIMPLE ]; then npm run lint-all; fi
npx lint-staged --concurrent false
if [ -z $GAC_VERIFY_SIMPLE ]; then npm run lint; fi
NODE_ENV=format npx lint-staged --concurrent false
7 changes: 7 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Paths below are ignored by prettier as well as remark and doctoc when called
# with npm run format)
build
external-scripts/bin
node_modules
dist
coverage
package-lock.json
fixtures
docs
CHANGELOG.md
bundle-stats.ignore.json
test/integration/assets/output-1.js

0 comments on commit db0223e

Please sign in to comment.