Skip to content

Commit

Permalink
Eslint flat config (#14)
Browse files Browse the repository at this point in the history
* provide flat config

* fix lint prettier and couple more

---------

Co-authored-by: Ricky Lippmann <[email protected]>
  • Loading branch information
ldrick and lippmannr authored Feb 16, 2024
1 parent c75c84a commit 27da6ea
Show file tree
Hide file tree
Showing 47 changed files with 2,370 additions and 1,019 deletions.
103 changes: 0 additions & 103 deletions .eslintrc.cjs

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x]
node-version: [18.x, 20.x]
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down
4 changes: 1 addition & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
// trigger linting and fixes
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit",
"source.organizeImports": "explicit"
"source.fixAll.eslint": "explicit"
},
"eslint.validate": [
"javascript",
Expand All @@ -21,7 +20,6 @@
"html",
"vue"
],
"eslint.packageManager": "npm",
// package manager
"npm.packageManager": "npm",
"typescript.enablePromptUseWorkspaceTsdk": true,
Expand Down
212 changes: 212 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
// @ts-check

import path from 'node:path';
import { fileURLToPath } from 'node:url';

import { FlatCompat } from '@eslint/eslintrc';
import eslint from '@eslint/js';
import configPrettier from 'eslint-config-prettier';
import functionalPlugin from 'eslint-plugin-functional';
import importPlugin from 'eslint-plugin-import';
import jsdocPlugin from 'eslint-plugin-jsdoc';
import unicornPlugin from 'eslint-plugin-unicorn';
import vitestPlugin from 'eslint-plugin-vitest';
import globals from 'globals';
import typescriptEslint from 'typescript-eslint';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
resolvePluginsRelativeTo: __dirname,
recommendedConfig: eslint.configs.recommended,
allConfig: eslint.configs.all,
});

export default typescriptEslint.config(
// register all of the plugins upfront
{
plugins: {
['@typescript-eslint']: typescriptEslint.plugin,
['functional']: functionalPlugin,
['import']: importPlugin,
['jsdoc']: jsdocPlugin,
['vitest']: vitestPlugin,
},
},
// ignored files
{
ignores: ['node_modules', 'dist', 'coverage'],
},
// extends
eslint.configs.recommended,
...compat.extends('plugin:@eslint-community/eslint-comments/recommended'),
...typescriptEslint.configs.strictTypeChecked,
...typescriptEslint.configs.stylisticTypeChecked,
unicornPlugin.configs['flat/recommended'],
configPrettier,
// base config
{
languageOptions: {
globals: {
...globals.es2021,
...globals.node,
},
parserOptions: {
project: true,
tsconfigRootDir: __dirname,
warnOnUnsupportedTypeScriptVersion: false,
},
},
rules: {
// disallow non-import statements appearing before import statements
'import/first': 'error',
// Require a newline after the last import/require in a group
'import/newline-after-import': 'error',
// Forbid import of modules using absolute paths
'import/no-absolute-path': 'error',
// disallow AMD require/define
'import/no-amd': 'error',
// forbid default exports - we want to standardize on named exports so that imported names are consistent
'import/no-default-export': 'error',
// disallow imports from duplicate paths
'import/no-duplicates': 'error',
// Forbid the use of extraneous packages
'import/no-extraneous-dependencies': [
'error',
{
devDependencies: true,
peerDependencies: true,
optionalDependencies: false,
},
],
// Forbid mutable exports
'import/no-mutable-exports': 'error',
// Prevent importing the default as if it were named
'import/no-named-default': 'error',
// Prohibit named exports
'import/no-named-export': 'off', // we want everything to be a named export
// Forbid a module from importing itself
'import/no-self-import': 'error',
// Require modules with a single export to use a default export
'import/prefer-default-export': 'off', // we want everything to be named
'import/order': [
'error',
{
groups: ['builtin', 'external', ['sibling', 'parent'], 'index', 'object', 'type'],
'newlines-between': 'always',
alphabetize: {
order: 'asc',
caseInsensitive: true,
},
},
],
'unicorn/filename-case': ['error', { cases: { camelCase: true, pascalCase: true } }],
'unicorn/no-null': 'off',
'unicorn/no-array-reduce': 'off',
'unicorn/no-array-callback-reference': 'off',
},
},
// overrides for JavaScript files
{
files: ['*.js'],
...typescriptEslint.configs.disableTypeChecked,
},
// overrides for TypeScript files
{
files: ['*.ts'],
ignores: ['**/*.d.ts'],
rules: {
...jsdocPlugin.configs['flat/recommended-typescript-error'].rules,
'no-nested-ternary': 'off',
'jsdoc/require-returns': 'off',
'jsdoc/require-param': 'off',
'jsdoc/require-jsdoc': [
'error',
{
publicOnly: {
esm: true,
},
require: {
ArrowFunctionExpression: true,
ClassDeclaration: true,
ClassExpression: true,
FunctionDeclaration: true,
FunctionExpression: true,
MethodDefinition: false,
},
},
],
'jsdoc/require-description': [
'error',
{
contexts: ['any'],
},
],
'jsdoc/check-tag-names': [
'error',
{
definedTags: ['internal'],
},
],
},
},
// overrides for TypeScript Definition files
{
files: ['**/*.d.ts'],
rules: {
'unicorn/filename-case': 'off',
},
},
// overrides for functional TypeScript files
{
files: ['src/!(errors)/*.ts'],
ignores: ['**/*.d.ts'],
settings: {
immutability: {
overrides: [
{
type: { from: 'package', package: 'big.js', name: 'Big' },
from: 'Mutable',
to: 'Immutable',
},
],
},
},
rules: {
...functionalPlugin.configs.recommended.rules,
'functional/functional-parameters': [
'error',
{
enforceParameterCount: false,
},
],
},
},
// overrides for Test files
{
files: ['*.spec.ts'],
languageOptions: {
globals: {
...vitestPlugin.environments.env.globals,
},
},
rules: {
...vitestPlugin.configs.recommended.rules,
'vitest/consistent-test-it': [
'error',
{
fn: 'it',
withinDescribe: 'it',
},
],
},
},
// overrides for Config files
{
files: ['eslint.config.js', 'vitest.config.ts'],
rules: {
'import/no-default-export': 'off',
},
},
);
Loading

0 comments on commit 27da6ea

Please sign in to comment.