Skip to content

Commit

Permalink
ci: add typescript eslint plugin wd-268 (#269)
Browse files Browse the repository at this point in the history
  • Loading branch information
what1s1ove authored Dec 15, 2023
1 parent 88f9f07 commit 346a986
Show file tree
Hide file tree
Showing 20 changed files with 325 additions and 83 deletions.
4 changes: 3 additions & 1 deletion .linthtmlrc.cjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/** @type {import('@linthtml/linthtml').LinterConfig} */
/** @typedef {import('@linthtml/linthtml').LinterConfig} LinterConfig */

/** @type {LinterConfig} */
let config = {
'attr-name-ignore-regex': false,
'extends': `linthtml-config-htmlacademy`,
Expand Down
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ lint_bem:
lint_css:
npx stylelint "source/styles/**/*.css"
lint_js:
npx eslint "**/*.{js,cjs}"
npx eslint "**/*.js"
lint_js_fix:
npx eslint "**/*.js" --fix
lint_type:
npx tsc --noEmit
lint: lint_fs lint_editor lint_format lint_markup lint_html lint_bem lint_css lint_js lint_type
4 changes: 3 additions & 1 deletion commitlint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { RuleConfigSeverity } from '@commitlint/types'

import { ProjectPrefix } from './project.config.js'

/** @type {import('@commitlint/types').UserConfig} */
/** @typedef {import('@commitlint/types').UserConfig} UserConfig */

/** @type {UserConfig} */
let configuration = {
extends: [`@commitlint/config-conventional`],
parserPreset: {
Expand Down
13 changes: 5 additions & 8 deletions eleventy.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ let Image = require(`@11ty/eleventy-img`)
let svgo = require(`svgo`)
let path = require(`node:path`)

/** @typedef {import('@11ty/eleventy').UserConfig} UserConfig */
/** @typedef {ReturnType<typeof import('@11ty/eleventy/src/defaultConfig')>} DefaultConfig */

let isDevelopment = process.env.NODE_ENV === `development`

let Path = /** @type {const} */ ({
Expand All @@ -30,8 +33,8 @@ let Path = /** @type {const} */ ({
})

/**
* @param {import('@11ty/eleventy').UserConfig} config
* @returns {ReturnType<typeof import('@11ty/eleventy/src/defaultConfig')>}
* @param {UserConfig} config
* @returns {DefaultConfig}
*/
let init = (config) => {
// ignores
Expand All @@ -48,7 +51,6 @@ let init = (config) => {
config.addTemplateFormats(`json`)

config.addExtension(`json`, {
/** @type {import('@11ty/eleventy/src/Engines/TemplateEngine')['compile']} */
compile: async (_content, url) => {
if (url !== Path.DB) {
return
Expand Down Expand Up @@ -89,7 +91,6 @@ let init = (config) => {
config.addTemplateFormats(`css`)

config.addExtension(`css`, {
/** @type {import('@11ty/eleventy/src/Engines/TemplateEngine')['compile']} */
compile: async (_content, url) => {
if (url !== Path.CSS) {
return
Expand Down Expand Up @@ -127,7 +128,6 @@ let init = (config) => {
config.addTemplateFormats(`js`)

config.addExtension(`js`, {
/** @type {import('@11ty/eleventy/src/Engines/TemplateEngine')['compile']} */
compile: async (_content, url) => {
if (url !== Path.JS) {
return
Expand Down Expand Up @@ -155,7 +155,6 @@ let init = (config) => {
config.addTemplateFormats(`png`)

config.addExtension(`png`, {
/** @type {import('@11ty/eleventy/src/Engines/TemplateEngine')['compile']} */
compile: async (_content, url) => {
return async () => {
let {
Expand All @@ -167,7 +166,6 @@ let init = (config) => {

if (url.includes(`.photo.`)) {
await Image(url, {
/** @type {import('@11ty/eleventy-img').BaseImageOptions['filenameFormat']} */
filenameFormat: (_id, source, _width, format) => {
let extension = path.extname(source)
let name = path.basename(source, extension)
Expand All @@ -189,7 +187,6 @@ let init = (config) => {
config.addTemplateFormats(`svg`)

config.addExtension(`svg`, {
/** @type {import('@11ty/eleventy/src/Engines/TemplateEngine')['compile']} */
compile: (content) => {
return () => {
return svgo.optimize(content).data
Expand Down
76 changes: 56 additions & 20 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
// @ts-expect-error: no declaration file
import js from '@eslint/js'
// @ts-expect-error: no declaration file
import typescript from '@typescript-eslint/eslint-plugin'
import typescriptParser from '@typescript-eslint/parser'
import importPlugin from 'eslint-plugin-import'
// @ts-expect-error: no declaration file
import jsdoc from 'eslint-plugin-jsdoc'
// @ts-expect-error: no declaration file
import perfectionist from 'eslint-plugin-perfectionist'
// @ts-expect-error: no declaration file
import simpleImportSort from 'eslint-plugin-simple-import-sort'
import sonarjs from 'eslint-plugin-sonarjs'
// @ts-expect-error: no declaration file
import unicorn from 'eslint-plugin-unicorn'
import globals from 'globals'

/** @type {import('eslint').Linter.FlatConfig} */
/** @typedef {import('eslint').Linter.FlatConfig} FlatConfig */
/** @typedef {import('eslint').Linter.ParserModule} TypeScriptParser */

/** @type {FlatConfig} */
let ignoresConfig = {
ignores: [`build`],
}

/** @type {import('eslint').Linter.FlatConfig} */
/** @type {FlatConfig} */
let globalConfig = {
languageOptions: {
globals: globals.browser,
Expand All @@ -27,12 +26,10 @@ let globalConfig = {
sourceType: `module`,
},
},
rules: {
...js.configs.recommended.rules,
},
rules: js.configs.recommended.rules,
}

/** @type {import('eslint').Linter.FlatConfig} */
/** @type {FlatConfig} */
let importConfig = {
plugins: {
import: importPlugin,
Expand Down Expand Up @@ -60,31 +57,31 @@ let importConfig = {
},
}

/** @type {import('eslint').Linter.FlatConfig} */
/** @type {FlatConfig} */
let sonarConfig = {
plugins: {
sonarjs,
},
rules: sonarjs.configs.recommended.rules,
}

/** @type {import('eslint').Linter.FlatConfig} */
/** @type {FlatConfig} */
let unicornConfig = {
plugins: {
unicorn,
},
rules: unicorn.configs.recommended.rules,
}

/** @type {import('eslint').Linter.FlatConfig} */
/** @type {FlatConfig} */
let perfectionistConfig = {
plugins: {
perfectionist,
},
rules: perfectionist.configs[`recommended-natural`].rules,
}

/** @type {import('eslint').Linter.FlatConfig} */
/** @type {FlatConfig} */
let jsdocConfig = {
plugins: {
jsdoc,
Expand Down Expand Up @@ -118,7 +115,7 @@ let jsdocConfig = {
},
}

/** @type {import('eslint').Linter.FlatConfig} */
/** @type {FlatConfig} */
let simpleImportSortConfig = {
plugins: {
'simple-import-sort': simpleImportSort,
Expand All @@ -129,7 +126,37 @@ let simpleImportSortConfig = {
},
}

/** @type {import('eslint').Linter.FlatConfig} */
/** @type {FlatConfig} */
let typescriptPlugin = {
languageOptions: {
parser: /** @type {TypeScriptParser} */ (typescriptParser),
parserOptions: {
project: `./tsconfig.json`,
},
},
plugins: {
'@typescript-eslint': typescript,
},
rules: {
...typescript.configs[`strict-type-checked`].rules,
'@typescript-eslint/no-extraneous-class': [
`error`,
{
allowStaticOnly: true,
},
],
'@typescript-eslint/no-misused-promises': [
`error`,
{
checksVoidReturn: {
arguments: false,
},
},
],
},
}

/** @type {FlatConfig} */
let mainRulesConfig = {
rules: {
'arrow-parens': [`error`, `always`],
Expand Down Expand Up @@ -195,7 +222,7 @@ let mainRulesConfig = {
},
}

/** @type {import('eslint').Linter.FlatConfig[]} */
/** @type {FlatConfig[]} */
let overridesConfigs = [
{
files: [
Expand All @@ -221,9 +248,17 @@ let overridesConfigs = [
'sonarjs/cognitive-complexity': [`off`],
},
},
{
files: [
`source/scripts/libs/packages/whatislove-math/whatislove-math.package.js`,
],
rules: {
'unicorn/no-static-only-class': [`off`],
},
},
]

/** @type {import('eslint').Linter.FlatConfig[]} */
/** @type {FlatConfig[]} */
let config = [
ignoresConfig,
globalConfig,
Expand All @@ -233,6 +268,7 @@ let config = [
perfectionistConfig,
jsdocConfig,
simpleImportSortConfig,
typescriptPlugin,
mainRulesConfig,
...overridesConfigs,
]
Expand Down
4 changes: 3 additions & 1 deletion lint-staged.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/** @type {import('lint-staged').Config} */
/** @typedef {import('lint-staged').Config} Config */

/** @type {Config} */
let config = {
'*': `make lint_editor lint_fs`,
'*.{json,md,yml,njk,css,js,cjs,d.ts}': `prettier --write`,
Expand Down
Loading

0 comments on commit 346a986

Please sign in to comment.