Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate limits for individual use, alter recommended to be the most common use #7

Merged
merged 3 commits into from
Jun 30, 2024
Merged
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
18 changes: 7 additions & 11 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -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],
})
1 change: 0 additions & 1 deletion scripts/clean-yarn.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-console,@typescript-eslint/no-floating-promises */
import { $ } from 'execa'
import { rimraf as r } from 'rimraf'

Expand Down
1 change: 0 additions & 1 deletion scripts/clean.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 0 additions & 1 deletion scripts/reset.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-console */
import { dirname } from 'node:path'
import { fileURLToPath } from 'node:url'

Expand Down
13 changes: 13 additions & 0 deletions src/configs/index.js
Original file line number Diff line number Diff line change
@@ -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
19 changes: 12 additions & 7 deletions src/js.js → src/configs/js.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 6 additions & 2 deletions src/json.js → src/configs/json.js
Original file line number Diff line number Diff line change
@@ -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',
Expand Down
8 changes: 6 additions & 2 deletions src/markdown.js → src/configs/markdown.js
Original file line number Diff line number Diff line change
@@ -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,
{
Expand Down
2 changes: 2 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
18 changes: 7 additions & 11 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -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,
}
8 changes: 8 additions & 0 deletions src/limits/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import jsOnly from './jsOnly.js'
import jsOnlyScripts from './jsOnlyScripts.js'

const ruleset = {
jsOnly,
jsOnlyScripts,
}
export default ruleset
23 changes: 23 additions & 0 deletions src/limits/jsOnly.js
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions src/limits/jsOnlyScripts.js
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
Loading