Skip to content

Commit

Permalink
chore: update eslint config
Browse files Browse the repository at this point in the history
  • Loading branch information
andrepolischuk committed Feb 2, 2024
1 parent 81c0235 commit 978a70b
Show file tree
Hide file tree
Showing 7 changed files with 770 additions and 501 deletions.
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@
"devDependencies": {
"@commitlint/cli": "^17.4.1",
"@commitlint/config-conventional": "^17.4.0",
"@rambler-tech/eslint-config": "^0.0.2",
"@rambler-tech/eslint-config": "^0.9.3",
"@rambler-tech/licenselint-config": "^0.0.2",
"@rambler-tech/prettier-config": "^0.0.2",
"@rambler-tech/prettier-config": "^0.1.0",
"@rambler-tech/ts-config": "^0.0.2",
"@types/debug": "^4.1.7",
"@types/jest": "^29.2.5",
"@types/license-checker": "^25.0.3",
"@types/node": "^18.11.18",
"@typescript-eslint/eslint-plugin": "^5.48.1",
"@typescript-eslint/parser": "^5.48.1",
"eslint": "^8.31.0",
"eslint-config-prettier": "^8.6.0",
"@typescript-eslint/eslint-plugin": "^6.20.0",
"@typescript-eslint/parser": "^6.20.0",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"husky": "^8.0.3",
"jest": "^29.3.1",
"lint-staged": "^13.1.0",
Expand Down
26 changes: 13 additions & 13 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,24 +71,24 @@ const cliOptions: Options = Object.fromEntries(
Object.entries(cli.flags).filter(([, value]) => value !== defaultArray)
)

loadOptions(cliOptions.extends)
.then((baseOptions) => {
const run = async (cliOptions: Options): Promise<void> => {
try {
const baseOptions = await loadOptions(cliOptions.extends)
const options = {...baseOptions, ...cliOptions}

debug('entry: %o', entry)
debug('options: %o', options)

return options
})
.then((options) =>
lint(entry, options).then((results) => {
const errors = results.filter((result) => result.error)
const results = await lint(entry, options)
const errors = results.filter((result) => result.error)

console.log(format(results, options))
process.exit(errors.length > 0 ? 1 : 0)
})
)
.catch((error) => {
// eslint-disable-next-line no-console
console.log(format(results, options))
process.exit(errors.length > 0 ? 1 : 0)
} catch (error) {
console.error(error)
process.exit(1)
})
}
}

run(cliOptions)
11 changes: 5 additions & 6 deletions src/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import stringWidth from 'string-width'
import {Options} from './options'
import {LicenseResult} from './lint'

export interface FormatLine {
interface FormatLine {
name: string
nameWidth: number
license: string
Expand Down Expand Up @@ -48,7 +48,7 @@ const formatSummaryLines = (
.map((line) =>
[
'',
logSymbols['success'],
logSymbols.success,
line[0].license + ' '.repeat(maxLicenseWidth - line[0].licenseWidth),
chalk.dim(line.length)
].join(' ')
Expand Down Expand Up @@ -94,10 +94,9 @@ export const format = (results: LicenseResult[], options: Options): string => {
output += '\n'

if (errorLines.length > 0) {
output +=
'\n ' +
chalk.red(pluralize(errorLines.length, 'error', 'errors')) +
'\n\n'
output += '\n'
output += chalk.red(pluralize(errorLines.length, 'error', 'errors'))
output += '\n\n'
output += formatFullLines(
errorLines,
maxErrorNameWidth || maxNameWidth,
Expand Down
2 changes: 1 addition & 1 deletion src/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const lint = async (
start: entry,
production,
development,
// NOTE fix wrong `exclude` type
// fix wrong `exclude` type
exclude: exclude.toString() as unknown as string[]
}

Expand Down
8 changes: 4 additions & 4 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@ const defaultOptionsFileName = '.licenserc.json'

export const loadOptions = async (
optionsFileName = defaultOptionsFileName,
optionsFileDir = process.cwd()
optionsFileDirectory = process.cwd()
): Promise<Partial<Options>> => {
try {
const optionsFilePath = optionsFileName.endsWith('.json')
? path.resolve(optionsFileDir, optionsFileName)
? path.resolve(optionsFileDirectory, optionsFileName)
: optionsFileName

const {default: options} = await import(optionsFilePath)
const {extends: extendsFileName, ...restOptions} = options
let extendsOptions = {}

if (extendsFileName) {
const extendsFileDir = path.dirname(optionsFilePath)
const extendsFileDirectory = path.dirname(optionsFilePath)

extendsOptions = await loadOptions(extendsFileName, extendsFileDir)
extendsOptions = await loadOptions(extendsFileName, extendsFileDirectory)
}

const resultOptions = {...defaultOptions, ...extendsOptions, ...restOptions}
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
"outDir": "dist"
},
"include": ["src"],
"exclude": ["node_modules", "dist", "**/*.test.ts"]
"exclude": ["node_modules", "dist"]
}
Loading

0 comments on commit 978a70b

Please sign in to comment.