Skip to content

Commit

Permalink
Merge branch 'release/3.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-holder-revvity committed Aug 14, 2024
2 parents 7cc4f89 + 48e2b15 commit 0a08c98
Show file tree
Hide file tree
Showing 18 changed files with 111 additions and 172 deletions.
3 changes: 0 additions & 3 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

yarn build
yarn lint
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"name": "Launch Program",
"skipFiles": ["<node_internals>/**"],
"runtimeExecutable": "yarn",
"runtimeArgs": ["eslint", "."],
"runtimeArgs": ["eslint", "."]
}
]
}
30 changes: 15 additions & 15 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "build",
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "build",
"group": {
"kind": "build",
"isDefault": true
},
"label": "npm: build",
"detail": "tsc --build"
},
{
"type": "npm",
"script": "rebuild",
"label": "npm: build",
"detail": "tsc --build"
},
{
"type": "npm",
"script": "rebuild",
"group": "build",
"label": "npm: rebuild",
"detail": "npm clean && npm build"
}
]
"label": "npm: rebuild",
"detail": "npm clean && npm build"
}
]
}
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Quick and Easy Opinionated ESLint Setup
# Quick and Easy Opinionated Linting Setup

## ESLint

Provides a strict, quick, and easy to setup opinionated ESLint rule set for;

- JavaScript
- TypeScript
- Node.js
Expand Down Expand Up @@ -31,16 +34,29 @@ module.exports = defineConfig(({ useNode, useTypeScript }) => {
```

Support function from `defineConfig`.

- `usePrettier`
- `useNode`
- `useTypeScript`
- `useVue`

JavaScript is always supported by default.

The following ESLint plug-ins are:
The following ESLint plug-ins are used:

- `prettier`
- `n`
- `import`
- `promise`
- `typescript`
- `vue`

## Prettier

Provides a compatible opinionated Prettier configuration to run Prettier separately.

Simply add a `prettier.config.cjs` with the following contents:

```js
module.exports = require('@sixxgate/lint/prettier.config.cjs')
```
36 changes: 21 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sixxgate/lint",
"version": "3.1.4",
"version": "3.2.0",
"packageManager": "[email protected]",
"main": "dist/index.cjs",
"author": "Matthew Holder <[email protected]>",
Expand All @@ -13,14 +13,18 @@
"access": "public"
},
"scripts": {
"rebuild": "run-s clean build",
"build": "run-p compile copy",
"rebuild": "run-s -l clean build",
"build": "run-p -l compile copy",
"compile": "tsc",
"copy": "cpy 'src/**/*.{js,jsx,cjs,mjs,d.ts,d.tsx,d.cts,d.mts}' dist/",
"clean": "del dist/",
"lint": "eslint .",
"fix": "eslint --fix .",
"prepare": "husky install",
"lint:eslint": "eslint .",
"lint:prettier": "prettier -cu .",
"lint": "run-p -l 'lint:*'",
"fix:eslint": "eslint --fix .",
"fix:prettier": "prettier -cu --write .",
"fix": "run-s -l 'fix:*'",
"prepare": "husky",
"prepack": "yarn run rebuild"
},
"files": [
Expand All @@ -34,18 +38,20 @@
"dist/**/*.mjs",
"dist/**/*.js.map",
"dist/**/*.cjs.map",
"dist/**/*.mjs.map"
"dist/**/*.mjs.map",
"prettier.config.cjs"
],
"peerDependencies": {
"eslint": "^8.52.0"
},
"devDependencies": {
"@tsconfig/node18": "^18.2.4",
"@tsconfig/strictest": "^2.0.5",
"@types/debug": "^4.1.12",
"@types/lodash": "^4.17.7",
"@types/node": "18.19.43",
"@typescript-eslint/eslint-plugin": "^7.18.0",
"@typescript-eslint/parser": "^7.18.0",
"@types/node": "18.19.44",
"@typescript-eslint/eslint-plugin": "^8.1.0",
"@typescript-eslint/parser": "^8.1.0",
"@vue/eslint-config-prettier": "^9.0.0",
"@vue/eslint-config-typescript": "^13.0.0",
"cpy-cli": "^5.0.0",
Expand All @@ -54,12 +60,12 @@
"eslint-import-resolver-node": "^0.3.9",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-n": "^16.6.2",
"eslint-plugin-n": "^17.10.2",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-promise": "^6.6.0",
"eslint-plugin-promise": "^7.1.0",
"eslint-plugin-vue": "^9.27.0",
"husky": "^8.0.3",
"npm-check-updates": "^17.0.1",
"husky": "^9.1.4",
"npm-check-updates": "^17.0.6",
"npm-run-all2": "^6.2.2",
"prettier": "^3.3.3",
"typescript": "^5.5.4",
Expand All @@ -80,7 +86,7 @@
"radash": "^12.1.0",
"read-pkg": "^5.2.0",
"tslib": "^2.6.3",
"type-fest": "^4.23.0",
"type-fest": "^4.24.0",
"zod": "^3.23.8"
}
}
11 changes: 11 additions & 0 deletions prettier.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/** @type {import('prettier').Config} */
const config = {
semi: false,
singleQuote: true,
quoteProps: 'consistent',
trailingComma: 'none',
bracketSameLine: true,
printWidth: 120
}

module.exports = config
6 changes: 6 additions & 0 deletions prettier.config.d.cts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type { Config } from 'prettier'

/** @type {import('prettier').Config} */
const config: Config

export = config
4 changes: 2 additions & 2 deletions src/components/extend.cts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const BaseSpec = z.union([
z
.string()
.min(1)
.transform(value => [value]),
.transform((value) => [value]),
z.array(z.string().min(1)).transform(uniq)
])

Expand All @@ -20,7 +20,7 @@ const ExtendOptions = z
})
.partial()

const Options = z.union([BaseSpec.transform(before => ExtendOptions.parse({ before })), ExtendOptions]).default({})
const Options = z.union([BaseSpec.transform((before) => ExtendOptions.parse({ before })), ExtendOptions]).default({})

type Options = z.input<typeof Options>

Expand Down
6 changes: 4 additions & 2 deletions src/components/import.cts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const ImportComponent = Object.assign(
function getDependencies() {
return [
'eslint-plugin-import',
...Array.from(settings.resolvers).map(resolver => `eslint-import-resolver-${resolver}`)
...Array.from(settings.resolvers).map((resolver) => `eslint-import-resolver-${resolver}`)
]
}

Expand All @@ -87,7 +87,9 @@ const ImportComponent = Object.assign(
),
'import/extensions': Array.from(settings.extensions),
'import/external-module-folders': Array.from(settings.externalModuleFolders),
'import/resolver': Object.fromEntries(Array.from(settings.resolvers).map(resolver => [resolver, true] as const))
'import/resolver': Object.fromEntries(
Array.from(settings.resolvers).map((resolver) => [resolver, true] as const)
)
}

config.rules = {
Expand Down
5 changes: 2 additions & 3 deletions src/components/javascript.cts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ function getStandardJavaScriptRules(): Linter.RulesRecord {
'no-alert': 'error',
'no-array-constructor': 'error',
'no-caller': 'error',
'no-confusing-arrow': 'error',
'no-div-regex': 'error',
'no-else-return': 'warn',
'no-empty-function': 'warn',
Expand Down Expand Up @@ -137,15 +136,15 @@ const JavaScriptComponent = Object.assign(
// But, include it anyways to keep thing normal in case
// this program moves to flat configuration or can
// eventually use dynamic imports.
return ['eslint', '@eslint/eslintrc', '@eslint/js']
return ['eslint']
}

function getPrecedingComponents() {
return [getComponent(ImportComponent), getComponent(PrettierComponent), getComponent(ExtendComponent)]
}

function preConfigure() {
getComponent(ExtendComponent).extend('eslint:recommended')
getComponent(ExtendComponent).extend({ before: 'eslint:recommended', after: 'prettier' })

const theImportComponent = getComponent(ImportComponent)
theImportComponent.enableResolver('node')
Expand Down
11 changes: 3 additions & 8 deletions src/components/prettier.cts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import baseConfig from '../../prettier.config.cjs'
import { defineComponent } from '../core/components.cjs'
import useLegacyConfig from '../core/legacy.cjs'
import ExtendComponent from './extend.cjs'
Expand All @@ -9,13 +10,7 @@ function getStandardPrettierRules(): Linter.RulesRecord {
'warn',
{
editorconfig: true,
semi: false,
singleQuote: true,
quoteProps: 'consistent',
trailingComma: 'none',
bracketSameLine: true,
arrowParens: 'avoid',
printWidth: 120
...baseConfig
}
]
}
Expand All @@ -38,7 +33,7 @@ const PrettierComponent = Object.assign(
}

function preConfigure() {
getComponent(ExtendComponent).extend({ after: ['plugin:prettier/recommended', 'prettier'] })
getComponent(ExtendComponent).extend({ after: ['plugin:prettier/recommended'] })
}

function configure(config: Linter.Config) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/legacy.cts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const useLegacyConfig = shared(() => {

return legacy
.extends(...names)
.map(config => (config.rules != null ? shake(config.rules) : null))
.map((config) => (config.rules != null ? shake(config.rules) : null))
.reduce<Linter.RulesRecord>((prev, rules) => ({ ...prev, ...rules }), {})
}

Expand Down
14 changes: 7 additions & 7 deletions src/core/logging.cts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import type { ValuesOf } from '../helpers/types.cjs'
import type { ChalkFunction } from 'chalk'
import type { ConditionalKeys } from 'type-fest'

const kDebugNamespace = 'lint-config'
const kLevels = Object.seal(['debug', 'info', 'log', 'warn', 'error'] as const)
export const kDebugNamespace = 'lint-config'
export const kLevels = Object.seal(['debug', 'info', 'log', 'warn', 'error'] as const)

type Levels = ValuesOf<typeof kLevels>
type LineFormatter = (message?: unknown, ...optionalParams: unknown[]) => [unknown?, ...unknown[]]
type LineWriter = (message?: unknown, ...optionalParams: unknown[]) => void
type ConsoleWriter = (typeof console)[Levels]
export type Levels = ValuesOf<typeof kLevels>
export type LineFormatter = (message?: unknown, ...optionalParams: unknown[]) => [unknown?, ...unknown[]]
export type LineWriter = (message?: unknown, ...optionalParams: unknown[]) => void
export type ConsoleWriter = (typeof console)[Levels]

interface LevelSettings {
export interface LevelSettings {
level: Levels
style: ChalkFunction
hideLevel?: boolean | undefined
Expand Down
10 changes: 7 additions & 3 deletions src/core/system.cts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ export function useDefineConfigApi(isolate: Isolate) {
theExtendComponent.extend(base, ...more)
}

function usePrettier(...args: ArgsFromFactory<typeof PrettierComponent>) {
thePrettierComponent.enable(...args)
}

function useNode(...args: ArgsFromFactory<typeof NodeComponent>) {
theNodeComponent.enable(...args)
}
Expand All @@ -56,7 +60,6 @@ export function useDefineConfigApi(isolate: Isolate) {
theJavaScriptComponent.enable()
theImportComponent.enable()
thePromiseComponent.enable()
thePrettierComponent.enable()

return {
// Extending lint
Expand All @@ -67,6 +70,7 @@ export function useDefineConfigApi(isolate: Isolate) {
findPackageManager,
// Components
extend,
usePrettier,
useNode,
useTypeScript,
useVue
Expand Down Expand Up @@ -108,12 +112,12 @@ export function defineConfig(callback: (api: DefineConfigApi) => Linter.Config)
for (const component of components) {
if (component.enabled) {
logger.debug(`Checking dependencies for "${component.name}"`)
dependencies.push(...component.dependencies.filter(dependency => !pm.has(dependency)))
dependencies.push(...component.dependencies.filter((dependency) => !pm.has(dependency)))
}
}

if (dependencies.length > 0) {
logger.info(`Installing dependencies ${dependencies.map(dependency => `"${dependency}"`).join(', ')}`)
logger.info(`Installing dependencies ${dependencies.map((dependency) => `"${dependency}"`).join(', ')}`)
pm.add(dependencies)

logger.warn('You must re-run ESLint to use newly installed dependencies.')
Expand Down
2 changes: 1 addition & 1 deletion src/managers/npm.cts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { run } from '../helpers/system.cjs'
const NodePackageManager = definePackageManager('npm', () => ({
executables: ['npm', 'npm.js', 'npm.cmd', 'npm.ps1', 'npm-cli.js'],
lockFileNames: ['package-lock.json', 'npm-shrinkwrap.json'],
add: names => {
add: (names) => {
run('npm', 'install', '--save-dev', '--legacy-peer-deps', ...names)
}
}))
Expand Down
2 changes: 1 addition & 1 deletion src/managers/pnpm.cts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { run } from '../helpers/system.cjs'
const PerformantNodePackageManager = definePackageManager('pnpm', () => ({
executables: ['pnpm', 'pnpm.cmd', 'pnpm.cjs'],
lockFileNames: ['pnpm-lock.yaml'],
add: names => {
add: (names) => {
run('pnpm', 'add', '--save-dev', ...names)
}
}))
Expand Down
2 changes: 1 addition & 1 deletion src/managers/yarn.cts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { run } from '../helpers/system.cjs'
const YarnPackageManager = definePackageManager('yarn', () => ({
executables: ['yarn', 'yarn.cmd', 'yarn.js'],
lockFileNames: ['yarn.lock'],
add: names => {
add: (names) => {
run('yarn', 'add', '--dev', ...names)
}
}))
Expand Down
Loading

0 comments on commit 0a08c98

Please sign in to comment.