Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ learn how: http://kcd.im/pull-request
Relevant code or config

```javascript

```

What you did:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ node_modules
coverage
dist
.DS_Store
.jest-cache

# these cause more harm than good
# when working with contributors
Expand Down
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npx lint-staged
1 change: 0 additions & 1 deletion .huskyrc.js

This file was deleted.

22 changes: 21 additions & 1 deletion .prettierrc.js
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@
module.exports = require('kcd-scripts/prettier')
/** @type {import('prettier').Options} */
module.exports = {
arrowParens: 'avoid',
bracketSameLine: false,
bracketSpacing: false,
embeddedLanguageFormatting: 'auto',
endOfLine: 'lf',
htmlWhitespaceSensitivity: 'css',
insertPragma: false,
jsxSingleQuote: false,
printWidth: 80,
proseWrap: 'always',
quoteProps: 'as-needed',
requirePragma: false,
semi: false,
singleAttributePerLine: false,
singleQuote: true,
tabWidth: 2,
trailingComma: 'all',
useTabs: false,
}
6 changes: 6 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
presets: [
['@babel/preset-env', {targets: {node: 'current'}}],
'@babel/preset-typescript',
],
}
330 changes: 330 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,330 @@
const eslintPluginImport = require('eslint-plugin-import')
const eslintPluginJest = require('eslint-plugin-jest')
const eslintPluginJestDom = require('eslint-plugin-jest-dom')
const tseslint = require('typescript-eslint')
const eslintConfigPrettier = require('eslint-config-prettier')

module.exports = tseslint.config(
// Global ignores
{
ignores: ['node_modules', 'coverage', 'dist', 'types/__tests__'],
},

// Base config for all JavaScript/TypeScript files
{
files: ['**/*.{js,jsx,ts,tsx}'],
languageOptions: {
ecmaVersion: 2020,
sourceType: 'module',
globals: {
// Browser globals
window: 'readonly',
document: 'readonly',
navigator: 'readonly',
console: 'readonly',
// Node.js globals
process: 'readonly',
__dirname: 'readonly',
__filename: 'readonly',
module: 'readonly',
require: 'readonly',
exports: 'readonly',
Buffer: 'readonly',
// ES6+ globals
Promise: 'readonly',
Set: 'readonly',
Map: 'readonly',
},
},
plugins: {
import: eslintPluginImport,
},
rules: {
// ESLint core rules (based on kentcdodds config)
'accessor-pairs': 'error',
'array-callback-return': 'error',
'arrow-body-style': 'off',
'block-scoped-var': 'error',
camelcase: 'off',
complexity: ['error', 20],
'consistent-return': 'error',
'consistent-this': 'off',
'constructor-super': 'error',
curly: ['error', 'multi-line'],
'default-case': 'error',
'default-case-last': 'error',
'dot-notation': 'error',
eqeqeq: 'off',
'for-direction': 'error',
'func-name-matching': 'error',
'func-names': 'error',
'getter-return': ['error', {allowImplicit: true}],
'guard-for-in': 'error',
'id-denylist': 'error',
'id-match': ['error', '^\\$?(__)?(([A-Z]|[a-z]|[0-9]+)|([A-Z_]))*\\$?$'],
'max-depth': ['error', 4],
'max-lines': ['error', {max: 2500, skipBlankLines: false}],
'max-nested-callbacks': ['error', 7],
'max-params': ['error', 7],
'max-statements-per-line': ['error', {max: 1}],
'new-cap': 'error',
'no-alert': 'error',
'no-array-constructor': 'error',
'no-async-promise-executor': 'off',
'no-await-in-loop': 'error',
'no-bitwise': 'error',
'no-caller': 'error',
'no-case-declarations': 'error',
'no-class-assign': 'error',
'no-compare-neg-zero': 'error',
'no-cond-assign': 'error',
'no-console': 'off',
'no-const-assign': 'error',
'no-constant-binary-expression': 'error',
'no-constant-condition': 'error',
'no-constructor-return': 'error',
'no-control-regex': 'error',
'no-debugger': 'error',
'no-delete-var': 'error',
'no-div-regex': 'error',
'no-dupe-args': 'error',
'no-dupe-class-members': 'error',
'no-dupe-else-if': 'error',
'no-dupe-keys': 'error',
'no-duplicate-case': 'error',
'no-duplicate-imports': 'error',
'no-else-return': 'off',
'no-empty': 'error',
'no-empty-character-class': 'error',
'no-empty-pattern': 'error',
'no-eval': 'error',
'no-extend-native': 'error',
'no-extra-bind': 'error',
'no-fallthrough': 'error',
'no-func-assign': 'error',
'no-global-assign': 'error',
'no-implicit-coercion': 'off',
'no-implied-eval': 'error',
'no-import-assign': 'error',
'no-invalid-this': 'off',
'no-irregular-whitespace': 'error',
'no-iterator': 'error',
'no-labels': 'error',
'no-lone-blocks': 'error',
'no-loop-func': 'error',
'no-loss-of-precision': 'error',
'no-misleading-character-class': 'error',
'no-multi-assign': 'off',
'no-multi-str': 'error',
'no-new': 'error',
'no-new-func': 'error',
'no-new-native-nonconstructor': 'error',
'no-new-wrappers': 'error',
'no-obj-calls': 'error',
'no-octal': 'error',
'no-octal-escape': 'error',
'no-param-reassign': 'off',
'no-proto': 'error',
'no-redeclare': 'error',
'no-regex-spaces': 'error',
'no-return-assign': ['error', 'except-parens'],
'no-return-await': 'error',
'no-script-url': 'error',
'no-self-assign': 'error',
'no-self-compare': 'error',
'no-sequences': 'error',
'no-shadow': 'off',
'no-shadow-restricted-names': 'error',
'no-sparse-arrays': 'error',
'no-this-before-super': 'error',
'no-throw-literal': 'error',
'no-undef': 'error',
'no-undef-init': 'error',
'no-unexpected-multiline': 'error',
'no-unmodified-loop-condition': 'error',
'no-unneeded-ternary': 'error',
'no-unreachable': 'error',
'no-unsafe-finally': 'error',
'no-unsafe-negation': 'error',
'no-unsafe-optional-chaining': 'error',
'no-unused-expressions': 'error',
'no-unused-labels': 'error',
'no-unused-vars': [
'error',
{
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_',
},
],
'no-use-before-define': 'off',
'no-useless-backreference': 'error',
'no-useless-call': 'error',
'no-useless-catch': 'off',
'no-useless-concat': 'error',
'no-useless-constructor': 'off',
'no-useless-escape': 'error',
'no-useless-return': 'error',
'no-var': 'error',
'no-void': 'off',
'no-with': 'error',
'object-shorthand': 'off',
'one-var': ['error', 'never'],
'prefer-arrow-callback': ['error', {allowNamedFunctions: true}],
'prefer-const': 'error',
'prefer-promise-reject-errors': 'error',
'prefer-rest-params': 'error',
'prefer-spread': 'error',
'prefer-template': 'off',
radix: 'error',
'require-await': 'off',
'require-yield': 'error',
'use-isnan': 'error',
'valid-typeof': 'error',

// Import plugin rules
'import/consistent-type-specifier-style': ['error', 'prefer-inline'],
'import/default': 'error',
'import/export': 'error',
'import/first': 'error',
'import/named': 'error',
'import/namespace': 'error',
'import/no-absolute-path': 'error',
'import/no-amd': 'error',
'import/no-duplicates': 'error',
'import/no-empty-named-blocks': 'error',
'import/no-extraneous-dependencies': 'error',
'import/no-mutable-exports': 'error',
'import/no-named-as-default': 'error',
'import/no-named-as-default-member': 'error',
'import/no-named-default': 'error',
'import/no-self-import': 'error',
'import/no-webpack-loader-syntax': 'error',
'import/order': [
'warn',
{
groups: [
'builtin',
['external', 'internal'],
'parent',
['sibling', 'index'],
],
},
],
},
},

// TypeScript files
...tseslint.configs.recommended.map(config => ({
...config,
files: ['**/*.ts', '**/*.tsx'],
})),
{
files: ['**/*.ts', '**/*.tsx'],
rules: {
// Disable JS rules that conflict with TS
'no-undef': 'off', // TypeScript handles this
'no-unused-vars': 'off', // Use TypeScript version instead
'@typescript-eslint/no-unused-vars': [
'error',
{
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_',
},
],
},
},

// TypeScript definition files
{
files: ['**/*.d.ts'],
rules: {
'@typescript-eslint/no-empty-interface': 'off',
'@typescript-eslint/no-empty-object-type': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/triple-slash-reference': 'off',
},
},

// Test files
{
files: [
'src/__tests__/**/*.{js,jsx,ts,tsx}',
'tests/**/*.{js,jsx,ts,tsx}',
'**/*.{spec,test}.{js,jsx,ts,tsx}',
],
plugins: {
jest: eslintPluginJest,
'jest-dom': eslintPluginJestDom,
},
languageOptions: {
globals: {
...eslintPluginJest.environments.globals.globals,
global: 'readonly', // Node.js global
},
},
rules: {
// Test-specific rule overrides
'max-lines-per-function': 'off',

// Jest rules
'jest/max-nested-describe': 'error',
'jest/no-commented-out-tests': 'warn',
'jest/no-conditional-expect': 'error',
'jest/no-conditional-in-test': 'error',
'jest/no-deprecated-functions': 'error',
'jest/no-disabled-tests': 'warn',
'jest/no-done-callback': 'error',
'jest/no-export': 'error',
'jest/no-focused-tests': 'error',
'jest/no-identical-title': 'error',
'jest/no-interpolation-in-snapshots': 'error',
'jest/no-large-snapshots': ['warn', {maxSize: 300}],
'jest/no-mocks-import': 'error',
'jest/no-test-prefixes': 'error',
'jest/prefer-called-with': 'error',
'jest/prefer-comparison-matcher': 'error',
'jest/prefer-each': 'error',
'jest/prefer-equality-matcher': 'error',
'jest/prefer-hooks-in-order': 'error',
'jest/prefer-hooks-on-top': 'error',
'jest/prefer-mock-promise-shorthand': 'error',
'jest/prefer-snapshot-hint': 'error',
'jest/prefer-to-contain': 'warn',
'jest/prefer-to-have-length': 'warn',
'jest/prefer-todo': 'warn',
'jest/valid-describe-callback': 'error',
'jest/valid-expect': 'error',
'jest/valid-expect-in-promise': 'error',
'jest/valid-title': 'warn',

// jest-dom rules
'jest-dom/prefer-checked': 'error',
'jest-dom/prefer-empty': 'error',
'jest-dom/prefer-enabled-disabled': 'error',
'jest-dom/prefer-focus': 'error',
'jest-dom/prefer-in-document': 'error',
'jest-dom/prefer-required': 'error',
'jest-dom/prefer-to-have-attribute': 'error',
'jest-dom/prefer-to-have-class': 'error',
'jest-dom/prefer-to-have-style': 'error',
'jest-dom/prefer-to-have-text-content': 'error',
'jest-dom/prefer-to-have-value': 'error',
},
},

// Files that use Jest globals outside of test files
{
files: ['src/index.js', 'tests/setup-env.js'],
languageOptions: {
globals: {
...eslintPluginJest.environments.globals.globals,
},
},
},

// Disable Prettier-conflicting rules (must be last)
eslintConfigPrettier,
)
Loading