Skip to content

Commit

Permalink
SonarJS including deprecated rule
Browse files Browse the repository at this point in the history
  • Loading branch information
arietrouw committed Feb 1, 2025
1 parent 3b808fe commit 9a4fc94
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 19 deletions.
3 changes: 2 additions & 1 deletion packages/eslint-config-flat/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { importConfig } from './import/index.ts'
// import { markdownConfig } from './markdown/index.ts'
// import { prettierConfig } from './prettier/index.ts'
import { rulesConfig } from './rules/index.ts'
import { sonarConfig } from './sonar/index.ts'
// import { sonarConfig } from './sonar/index.ts'
import { typescriptConfig } from './typescript/index.ts'
import { unicornConfig } from './unicorn/index.ts'
Expand All @@ -17,7 +18,7 @@ export const config: Linter.Config[] = [
rulesConfig,
// prettierConfig,
importConfig,
// sonarConfig
sonarConfig,
]

export { importConfig } from './import/index.ts'
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-config-flat/src/markdown/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { ESLint, Linter } from 'eslint'
import mdPlugin from 'eslint-plugin-md'

export const markdownConfig: Linter.FlatConfig = {
export const markdownConfig: Linter.Config = {
ignores: ['.yarn/**', 'jest.config.cjs', '**/dist/**', 'dist', 'build/**', 'node_modules/**'],
files: ['*.md'],
processor: 'md/markdown',
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-config-flat/src/rules/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Linter } from 'eslint'

export const rulesConfig: Linter.FlatConfig = {
export const rulesConfig: Linter.Config = {
ignores: ['.yarn/**', 'jest.config.cjs', '**/dist/**', 'dist', 'build/**', 'node_modules/**'],
rules: {
'complexity': ['error', 18],
Expand Down
14 changes: 12 additions & 2 deletions packages/eslint-config-flat/src/sonar/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
import type { Linter } from 'eslint'
import sonarjsPlugin from 'eslint-plugin-sonarjs'

const { rules, ...recommended } = sonarjsPlugin.configs.recommended

export const sonarConfig: Linter.Config = {
ignores: ['.yarn/**', 'jest.config.cjs', '**/dist/**', 'dist', 'build/**', 'node_modules/**'],
...sonarjsPlugin.configs,
...recommended,
rules: {
...sonarjsPlugin.configs.recommended.rules,
...rules,
'sonarjs/no-small-switch': ['off'],
'sonarjs/os-command': ['off'],
'sonarjs/no-os-command-from-path': ['off'],
'sonarjs/no-nested-conditional': ['off'],
'sonarjs/todo-tag': ['warn'],
'sonarjs/deprecation': ['warn'],
'sonarjs/cognitive-complexity': ['warn'],
'sonarjs/no-nested-functions': ['off'],
'sonarjs/function-return-type': ['warn'],
},
}
2 changes: 1 addition & 1 deletion packages/eslint-config-flat/src/unicorn/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { ESLint, Linter } from 'eslint'
import unicornPlugin from 'eslint-plugin-unicorn'

export const unicornConfig: Linter.FlatConfig = {
export const unicornConfig: Linter.Config = {
ignores: ['.yarn/**', 'jest.config.cjs', '**/dist/**', 'dist', 'build/**', 'node_modules/**'],
plugins: { unicorn: unicornPlugin as ESLint.Plugin },
rules: {
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-config-flat/src/workspaces/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { ESLint, Linter } from 'eslint'
import workspacesPlugin from 'eslint-plugin-workspaces'

export const workspacesConfig: Linter.FlatConfig = {
export const workspacesConfig: Linter.Config = {
ignores: ['.yarn/**', 'jest.config.cjs', '**/dist/**', 'dist', 'build/**', 'node_modules/**'],
plugins: { workspaces: workspacesPlugin as ESLint.Plugin },
rules: {
Expand Down
8 changes: 4 additions & 4 deletions packages/ts-scripts-yarn3/src/actions/license.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ export const license = async (pkg?: string) => {
for (let license of licenses) {
if (license) {
// remove surrounding parens on some string
if (license[0] === '(' && license.at(-1) === ')') {
license = license.slice(1, -2)
}
const processedLicense = (license[0] === '(' && license.at(-1) === ')')
? license.slice(1, -2)
: license
// get list of OR licenses from string
const orLicenses = license.split(' OR ')
const orLicenses = processedLicense.split(' OR ')
let orLicenseFound = false
for (const orLicense of orLicenses) {
if (exclude.has(orLicense)) {
Expand Down
4 changes: 2 additions & 2 deletions packages/ts-scripts-yarn3/src/actions/lint-clean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { rmSync } from 'node:fs'
import { yarnWorkspaces } from '../lib/index.ts'
import { lint } from './lint.ts'

export const lintClean = () => {
export const lintClean = async () => {
console.log('Lint Clean [.eslintcache]')
const workspaces = yarnWorkspaces()
const result = workspaces
Expand All @@ -20,5 +20,5 @@ export const lintClean = () => {
})
// eslint-disable-next-line unicorn/no-array-reduce
.reduce((prev, result) => prev || result, 0)
return result || lint()
return result || await lint()
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import chalk from 'chalk'

import { deleteGlob } from '../../lib/index.ts'

export const packageCleanOutputs = async () => {
export const packageCleanOutputs = () => {
const pkg = process.env.INIT_CWD ?? '.'
const pkgName = process.env.npm_package_name
const folders: string[] = [path.join(pkg, 'dist'), path.join(pkg, 'build'), path.join(pkg, 'docs')]
console.log(chalk.green(`Cleaning Outputs [${pkgName}]`))

await Promise.all(folders.map(folder => deleteGlob(folder)))
for (let folder of folders) {
deleteGlob(folder)
}

return 0
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import chalk from 'chalk'

import { deleteGlob } from '../../lib/index.ts'

export const packageCleanTypescript = async () => {
export const packageCleanTypescript = () => {
const pkg = process.env.INIT_CWD ?? '.'
const pkgName = process.env.npm_package_name
console.log(chalk.green(`Cleaning Typescript [${pkgName}]`))
const files: string[] = [path.join(pkg, '*.tsbuildinfo'), path.join(pkg, '.tsconfig.*'), path.join(pkg, '.eslintcache')]

await Promise.all(files.map(file => deleteGlob(file)))
for (let file of files) {
deleteGlob(file)
}

return 0
}
4 changes: 3 additions & 1 deletion packages/ts-scripts-yarn3/src/lib/generateIgnoreFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import {
INIT_CWD, yarnWorkspace, yarnWorkspaces,
} from './yarn/index.ts'

const mergeEntries = (a: string[], b: string[]): string[] => [...union(a, b)].sort()
const localeCompare = (a: string, b: string) => a.localeCompare(b)

const mergeEntries = (a: string[], b: string[]): string[] => [...union(a, b)].sort(localeCompare)

export const generateIgnoreFiles = (filename: string, pkg?: string) => {
console.log(chalk.green(`Generate ${filename} Files`))
Expand Down
2 changes: 1 addition & 1 deletion packages/ts-scripts-yarn3/src/lib/withError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export const withError = <T extends Error = Error>(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
ex: any,
closure: (error: T) => number,
predicate = (ex: T) => ex.name !== undefined && ex.message !== undefined,
predicate = (ex: T) => (!!ex.name && !!ex.message),
) => {
return predicate(ex as T) ? closure(ex as T) : undefined
}

0 comments on commit 9a4fc94

Please sign in to comment.