diff --git a/eslint.config.mjs b/eslint.config.mjs index 9ad8dfc..532448c 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -1,17 +1,13 @@ import tseslint from 'typescript-eslint' -import { configs } from './src/index.js' +import af from './src/index.js' +/** + * Project eslint configuration. + * + * View config with `npx @eslint/config-inspector` + */ export default tseslint.config({ name: 'project', - extends: [...configs.recommended], - // ignore since we are using just js, until we eventually switch this to ts - rules: { - '@typescript-eslint/no-unsafe-argument': 'off', - '@typescript-eslint/no-unsafe-member-access': 'off', - '@typescript-eslint/no-unused-vars': 'off', - '@typescript-eslint/no-unsafe-assignment': 'off', - '@typescript-eslint/no-unsafe-call': 'off', - '@typescript-eslint/no-unsafe-return': 'off', - }, + extends: [...af.configs.recommended, ...af.limits.jsOnly], }) diff --git a/scripts/clean-yarn.js b/scripts/clean-yarn.js index 89ea8f4..c96f428 100644 --- a/scripts/clean-yarn.js +++ b/scripts/clean-yarn.js @@ -1,4 +1,3 @@ -/* eslint-disable no-console,@typescript-eslint/no-floating-promises */ import { $ } from 'execa' import { rimraf as r } from 'rimraf' diff --git a/scripts/clean.js b/scripts/clean.js index f11635e..9cbced3 100644 --- a/scripts/clean.js +++ b/scripts/clean.js @@ -1,4 +1,3 @@ -/* eslint-disable no-console */ import { rimraf as r } from 'rimraf' // TODO: promote this as a script to @alienfast/ci once it is stable diff --git a/scripts/reset.js b/scripts/reset.js index 97c01ef..87e0571 100644 --- a/scripts/reset.js +++ b/scripts/reset.js @@ -1,4 +1,3 @@ -/* eslint-disable no-console */ import { dirname } from 'node:path' import { fileURLToPath } from 'node:url' diff --git a/src/configs/index.js b/src/configs/index.js new file mode 100644 index 0000000..80af4b1 --- /dev/null +++ b/src/configs/index.js @@ -0,0 +1,13 @@ +import jsOnlyScripts from '../limits/jsOnlyScripts.js' +import js from './js.js' +import json from './json.js' +import markdown from './markdown.js' + +const configs = { + js, + json, + markdown, + recommended: [...js, ...jsOnlyScripts, ...json, ...markdown], + other: [...markdown, ...json], +} +export default configs diff --git a/src/js.js b/src/configs/js.js similarity index 97% rename from src/js.js rename to src/configs/js.js index 8b3de68..f6d2f4e 100644 --- a/src/js.js +++ b/src/configs/js.js @@ -11,22 +11,27 @@ import unusedImports from 'eslint-plugin-unused-imports' import globals from 'globals' import tseslint from 'typescript-eslint' -import { ALL_JS_FILES, BUILD_IGNORES, NOT_JS } from './constants.js' -import { compat } from './legacy.js' +import { ALL_JS_FILES, BUILD_IGNORES, NOT_JS } from '../constants.js' +import { compat } from '../legacy.js' -// npx @eslint/config-inspector +/** + * Configuration preset for typescript files with any js/ts extension + * + * View configuration with `npx @eslint/config-inspector` + */ const configs = tseslint.config( - { - name: 'alienfast-js-files', - files: [...ALL_JS_FILES], - }, { name: 'alienfast-js-ignores', ignores: [...BUILD_IGNORES], }, + { + name: 'alienfast-js-files', + files: [...ALL_JS_FILES], + }, { name: 'alienfast-js', ignores: NOT_JS, + extends: [ // Recommended config applied to all files eslint.configs.recommended, diff --git a/src/json.js b/src/configs/json.js similarity index 65% rename from src/json.js rename to src/configs/json.js index 2c89f7c..dd447e2 100644 --- a/src/json.js +++ b/src/configs/json.js @@ -1,9 +1,13 @@ import json from 'eslint-plugin-json' import tseslint from 'typescript-eslint' -import { BUILD_IGNORES, JSON_FILES } from './constants.js' +import { BUILD_IGNORES, JSON_FILES } from '../constants.js' -// npx @eslint/config-inspector +/** + * Configuration preset for json files + * + * View configuration with `npx @eslint/config-inspector` + */ const configs = tseslint.config( { name: 'alienfast-json-ignores', diff --git a/src/markdown.js b/src/configs/markdown.js similarity index 65% rename from src/markdown.js rename to src/configs/markdown.js index 5667bf1..420c4f3 100644 --- a/src/markdown.js +++ b/src/configs/markdown.js @@ -1,9 +1,13 @@ import markdown from 'eslint-plugin-markdown' import tseslint from 'typescript-eslint' -import { BUILD_IGNORES, MD_FILES } from './constants.js' +import { BUILD_IGNORES, MD_FILES } from '../constants.js' -// npx @eslint/config-inspector +/** + * Configuration preset for markdown files + * + * View configuration with `npx @eslint/config-inspector` + */ const configs = tseslint.config( ...markdown.configs.recommended, { diff --git a/src/constants.js b/src/constants.js index c1a9a64..be4da6e 100644 --- a/src/constants.js +++ b/src/constants.js @@ -10,6 +10,8 @@ export const BUILD_IGNORES = [ '**/.yarn', ] +export const SCRIPTS = ['scripts/**/*.js'] + export const TS_FILES = ['**/*.{ts,tsx,mts,cts}'] export const JS_FILES = ['**/*.{js,mjs,cjs}'] export const ALL_JS_FILES = [...JS_FILES, ...TS_FILES] diff --git a/src/index.js b/src/index.js index 9f98973..9da02a7 100644 --- a/src/index.js +++ b/src/index.js @@ -1,13 +1,9 @@ -import js from './js.js' -import json from './json.js' -import markdown from './markdown.js' +import configs from './configs/index.js' +import * as constants from './constants.js' +import limits from './limits/index.js' -export default {} -export * from './constants.js' - -export const configs = { - js, - json, - markdown, - recommended: [...js, ...json, ...markdown], +export default { + constants, + configs, + limits, } diff --git a/src/limits/index.js b/src/limits/index.js new file mode 100644 index 0000000..f2213e9 --- /dev/null +++ b/src/limits/index.js @@ -0,0 +1,8 @@ +import jsOnly from './jsOnly.js' +import jsOnlyScripts from './jsOnlyScripts.js' + +const ruleset = { + jsOnly, + jsOnlyScripts, +} +export default ruleset diff --git a/src/limits/jsOnly.js b/src/limits/jsOnly.js new file mode 100644 index 0000000..f9a0e06 --- /dev/null +++ b/src/limits/jsOnly.js @@ -0,0 +1,23 @@ +import tseslint from 'typescript-eslint' + +/** + * Turn off rules not necessary for js only files. + * + * Do not extend configs, it will alter files/ignores behavior. + * + * View config with `npx @eslint/config-inspector` + */ +const configs = tseslint.config({ + name: 'alienfast-js-only', + rules: { + '@typescript-eslint/no-unsafe-argument': 'off', + '@typescript-eslint/no-unsafe-member-access': 'off', + '@typescript-eslint/no-unused-vars': 'off', + '@typescript-eslint/no-unsafe-assignment': 'off', + '@typescript-eslint/no-unsafe-call': 'off', + '@typescript-eslint/no-unsafe-return': 'off', + '@typescript-eslint/no-floating-promises': 'off', + }, +}) + +export default configs diff --git a/src/limits/jsOnlyScripts.js b/src/limits/jsOnlyScripts.js new file mode 100644 index 0000000..af0407a --- /dev/null +++ b/src/limits/jsOnlyScripts.js @@ -0,0 +1,22 @@ +import tseslint from 'typescript-eslint' + +import { SCRIPTS } from '../constants.js' +import jsOnly from './jsOnly.js' + +/** + * Turn off rules not necessary for scripts + * + * Do not extend configs, it will alter files/ignores behavior. + * + * View config with `npx @eslint/config-inspector` + */ +const configs = tseslint.config({ + name: 'alienfast-js-only-scripts', + extends: [...jsOnly], + files: SCRIPTS, + rules: { + 'no-console': 'off', + }, +}) + +export default configs diff --git a/tsconfig.json b/tsconfig.json index 82c0db7..d349507 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,5 +5,5 @@ "noEmit": true, "allowJs": true }, - "include": ["src/**.js", "scripts/**/*.js", "*.mjs"] + "include": ["src/**.js", "scripts/**/*.js", "*.mjs", "src/configs/js.js", "src/configs/json.js", "src/configs/markdown.js", "src/ruleset/jsOnly.js", "src/ruleset/jsOnlyScripts.js"] }