diff --git a/.vscode/settings.json b/.vscode/settings.json index 218c6fd..b60ff5c 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -14,5 +14,6 @@ "**/.*": false, "eslint*.*": false }, - "explorerExclude.backup": {} + "explorerExclude.backup": {}, + "cSpell.words": ["stylelintrc"] } diff --git a/eslint.config.js b/eslint.config.js index 7a7282d..97f9422 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -1,6 +1,11 @@ +const tseslint = require('typescript-eslint'); const { LintGolem } = require('./dist/index.js'); -module.exports = new LintGolem({ - rootDir: __dirname, - projectRoots: ['./tsconfig.eslint.json'], -}).config; +module.exports = tseslint.config( + ...new LintGolem({ + rootDir: __dirname, + tsconfigPaths: [ + './tsconfig.eslint.json' + ], + }).config +); diff --git a/package.json b/package.json index 3039a70..7e58288 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@magik_io/lint_golem", "description": "A really magik lint golem", - "version": "2.1.0", + "version": "2.1.1", "engines": { "node": "21.*.*", "npm": "10.*.*" @@ -24,12 +24,14 @@ "@eslint/eslintrc": "^3.0.2", "@eslint/js": "^9.2.0", "eslint": "^9.2.0", + "eslint-config-prettier": "^9.1.0", "eslint-plugin-n": "^17.4.0", "fast-glob": "^3.3.2", "typescript-eslint": "^7.8.0" }, "devDependencies": { "@types/eslint": "^8.56.10", + "@types/eslint-config-prettier": "^6.11.3", "@types/eslint__js": "^8.42.3", "@types/node": "^20.12.8", "@vitest/coverage-v8": "^1.6.0", diff --git a/src/index.ts b/src/index.ts index 97d9ccf..5f8e031 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,8 +1,8 @@ - import eslint from '@eslint/js'; import plugin_n from 'eslint-plugin-n'; import { glob } from 'fast-glob'; import tseslint from 'typescript-eslint'; +import prettierConfig from 'eslint-config-prettier'; import { LintGolemError } from './LintGolemError.js'; type PluginPrefixes = 'n/' | '@typescript-eslint/'; @@ -75,7 +75,13 @@ export class LintGolem { } } - public disabledNodeRules = ['n/no-missing-import', 'n/no-unpublished-require', 'n/no-unpublished-import']; + public disabledNodeRules = [ + 'n/no-missing-import', + 'n/no-unpublished-require', + 'n/no-unpublished-import', + 'n/no-extraneous-import', + 'n/no-extraneous-require', + ]; public nodeModifiedRules: EslintModifiedRule = {} public get nodeRules() { return { @@ -87,7 +93,7 @@ export class LintGolem { } } - public disabledEslintRules = ['arrow-body-style', 'camelcase', 'class-methods-use-this', 'consistent-return', 'func-names', 'indent', 'lines-between-class-members', + public disabledEslintRules = ['arrow-body-style', 'camelcase', 'class-methods-use-this', 'consistent-return', 'func-names', 'indent', 'lines-between-class-members', 'no-useless-escape', 'max-classes-per-file', 'newline-per-chained-call', 'no-bitwise', 'no-console', 'no-inner-declarations', 'no-lonely-if', 'no-nested-ternary', 'no-new', 'no-param-reassign', 'no-plusplus', 'no-prototype-builtins', 'no-restricted-syntax', 'no-underscore-dangle', 'no-unused-expressions', 'object-shorthand', 'one-var', 'one-var-declaration-per-line', 'spaced-comment']; public eslintModifiedRules: EslintModifiedRule = { @@ -178,7 +184,7 @@ export class LintGolem { get langOptsObject() { return { languageOptions: { - ecmaVersion: 'latest' as 'latest', + ecmaVersion: 'latest' as const, parserOptions: { project: this.tsconfigPaths, tsconfigRootDir: this.rootDir, @@ -200,6 +206,7 @@ export class LintGolem { eslint.configs.recommended, ...tseslint.configs.recommendedTypeChecked, plugin_n.configs['flat/recommended-script'], + prettierConfig, this.rulesObject, this.disabledFilesObject, ] as const; @@ -238,13 +245,18 @@ export class LintGolem { } public static async init(config: Omit & { tsconfigPaths?: Array }, verbose = false) { - const tsconfigPaths = await glob([ - `tsconfig.json`, - `*.tsconfig.json`, - ...(config.tsconfigPaths ?? []), - ], { cwd: config.rootDir, ignore: config.ignoreGlobs }); - if (tsconfigPaths.length === 0) throw new Error('No tsconfig.json found', { cause: 'Missing projectRoot / glob failure' }); - if (verbose) console.info('Found tsconfigPaths:', tsconfigPaths.join(', \n')); - return new LintGolem({ ...config, tsconfigPaths }); + try { + const tsconfigPaths = await glob([ + `tsconfig.json`, + `*.tsconfig.json`, + ...(config.tsconfigPaths ?? []), + ], { cwd: config.rootDir, ignore: config.ignoreGlobs }); + if (tsconfigPaths.length === 0) throw new Error('No tsconfig.json found', { cause: 'Missing projectRoot / glob failure' }); + if (verbose) console.info('Found tsconfigPaths:', tsconfigPaths.join(', \n')); + return new LintGolem({ ...config, tsconfigPaths }); + } catch (error) { + console.info('Error:', error); + throw error; + } } } diff --git a/test/index.test.ts b/test/index.test.ts index ae74dbf..5958010 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -2,7 +2,9 @@ import eslint from '@eslint/js'; import plugin_n from 'eslint-plugin-n'; import tseslint from 'typescript-eslint'; import { describe, it, expect, suite } from 'vitest' -import { LintGolem, type Types } from '../src/index.ts' +import { LintGolem, type Types } from '../src/index' + +import prettierConfig from 'eslint-config-prettier'; import { resolve } from 'node:path'; suite('LintGolem', () => { @@ -80,7 +82,7 @@ suite('LintGolem', () => { it('should throw an error if no default tsconfig can be found', async () => { await expect(async () => LintGolem.init({ rootDir: __dirname, - ignoreGlobs: ['*.package.json', 'package.json'], + ignoreGlobs: ['*.tsconfig.json', 'tsconfig.json', 'tsconfig.*.json'], disableTypeCheckOn: ['**/*.js'], }, true)).rejects.toThrowError() @@ -124,6 +126,7 @@ suite('LintGolem', () => { eslint.configs.recommended, ...tseslint.configs.recommendedTypeChecked, plugin_n.configs['flat/recommended-script'], + prettierConfig, summon.rulesObject, summon.disabledFilesObject, ] as const) diff --git a/tsconfig.eslint.json b/tsconfig.eslint.json index 6688b3d..7f70298 100644 --- a/tsconfig.eslint.json +++ b/tsconfig.eslint.json @@ -1,7 +1,61 @@ { - "extends": "./tsconfig.json", "compilerOptions": { + /* Language and Environment */ + "target": "ES2022" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */, + /* Modules */ + "module": "CommonJS" /* Specify what module code is generated. */, + // "rootDir": "./", /* Specify the root folder within your source files. */ + "moduleResolution": "bundler" /* Specify how TypeScript looks up a file from a given module specifier. */, + // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ + // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ + // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ + // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ + // "types": [], /* Specify type package names to be included without being referenced in a source file. */ + // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ + // "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */ + // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */ + // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */ + // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */ + // "resolveJsonModule": true, /* Enable importing .json files. */ + // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */ + // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ + + /* JavaScript Support */ + "allowJs": true /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */, + // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ + "maxNodeModuleJsDepth": 1 /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */, + + /* Emit */ + // "removeComments": true, /* Disable emitting comments. */ + // "noEmit": true, /* Disable emitting files from a compilation. */ + // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ + // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */ + // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ + // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */ + // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ + // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */ + // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */ + // "newLine": "crlf", /* Set the newline character for emitting files. */ + // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */ + // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */ + // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ + // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */ + // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ + // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */ + + /* Interop Constraints */ + // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ + // "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */ + "allowSyntheticDefaultImports": true /* Allow 'import x from y' when a module doesn't have a default export. */, + "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */, + // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ + "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */, + + /* Type Checking */ + "strict": true /* Enable all strict type-checking options. */, + "skipLibCheck": true /* Skip type checking all .d.ts files. */, "noEmit": true }, - "include": ["./vitest.config.ts", "./test/index.test.ts", "./src/index.ts"] + "include": ["./vitest.config.ts", "./test/index.test.ts", "./src/**/*.ts"] } diff --git a/yarn.lock b/yarn.lock index 8f83399..2f464a6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -370,10 +370,12 @@ __metadata: "@eslint/eslintrc": "npm:^3.0.2" "@eslint/js": "npm:^9.2.0" "@types/eslint": "npm:^8.56.10" + "@types/eslint-config-prettier": "npm:^6.11.3" "@types/eslint__js": "npm:^8.42.3" "@types/node": "npm:^20.12.8" "@vitest/coverage-v8": "npm:^1.6.0" eslint: "npm:^9.2.0" + eslint-config-prettier: "npm:^9.1.0" eslint-plugin-n: "npm:^17.4.0" fast-glob: "npm:^3.3.2" typescript: "npm:^5.4.5" @@ -560,6 +562,13 @@ __metadata: languageName: node linkType: hard +"@types/eslint-config-prettier@npm:^6.11.3": + version: 6.11.3 + resolution: "@types/eslint-config-prettier@npm:6.11.3" + checksum: 10c0/e49ef5b2cf9bfa173d678f50b392511e5567743a864552257978fcf98a876adcd41bb2fa074505ab4aae94862fb349eda2cf41aec698a4a1db77a2731b1fa1c6 + languageName: node + linkType: hard + "@types/eslint@npm:*, @types/eslint@npm:^8.56.10": version: 8.56.10 resolution: "@types/eslint@npm:8.56.10" @@ -1284,6 +1293,17 @@ __metadata: languageName: node linkType: hard +"eslint-config-prettier@npm:^9.1.0": + version: 9.1.0 + resolution: "eslint-config-prettier@npm:9.1.0" + peerDependencies: + eslint: ">=7.0.0" + bin: + eslint-config-prettier: bin/cli.js + checksum: 10c0/6d332694b36bc9ac6fdb18d3ca2f6ac42afa2ad61f0493e89226950a7091e38981b66bac2b47ba39d15b73fff2cd32c78b850a9cf9eed9ca9a96bfb2f3a2f10d + languageName: node + linkType: hard + "eslint-plugin-es-x@npm:^7.5.0": version: 7.6.0 resolution: "eslint-plugin-es-x@npm:7.6.0"