Skip to content

Commit

Permalink
update eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
webbestmaster committed Sep 22, 2024
1 parent bab183c commit 2adc9c6
Show file tree
Hide file tree
Showing 20 changed files with 103 additions and 61 deletions.
42 changes: 27 additions & 15 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import sonarjs from "eslint-plugin-sonarjs";
import eslintPluginUnicorn from "eslint-plugin-unicorn";
import typescriptEslint from "typescript-eslint";


/**
* List of plugins to add
* - react - from eslint-plugin-react
Expand Down Expand Up @@ -42,7 +41,7 @@ export default [
files,
...reactHooks.configs.recommended,
plugins: {
'react-hooks': reactHooks,
"react-hooks": reactHooks,
},
},
{
Expand All @@ -51,26 +50,26 @@ export default [
"simple-import-sort": simpleImportSort,
},
rules: {
"simple-import-sort/imports": "error",
"simple-import-sort/exports": "error",
"simple-import-sort/imports": "error",
},
},
{
settings: {react: {version: "detect"}},
languageOptions: {
parserOptions: {
project: ["./tsconfig.json"],
ecmaVersion: 2020,
sourceType: "module",
ecmaFeatures: {jsx: true},
},
globals: {
JSX: true,
require: true,
module: true,
console: true,
module: true,
require: true,
},
parserOptions: {
ecmaFeatures: {jsx: true},
ecmaVersion: 2020,
project: ["./tsconfig.eslint.json"],
sourceType: "module",
},
},
settings: {react: {version: "detect"}},
plugins: {
unicorn: eslintPluginUnicorn,
// Sonarjs: sonarjs,
Expand All @@ -80,6 +79,17 @@ export default [
...jest.configs["flat/all"].rules,
"jest/require-hook": [2, {allowedFunctionCalls: ["innerInitialization"]}],

"sonarjs/sonar-no-unused-vars": "off",
"sonarjs/sonar-prefer-read-only-props": "off",
"sonarjs/no-dead-store": "off",
"sonarjs/sonar-no-fallthrough": "off",
"sonarjs/todo-tag": "off",
"sonarjs/no-commented-code": "off",
"sonarjs/pseudo-random": "off",
"sonarjs/pseudo-randoms": "off",
"sonarjs/no-invariant-returns": "off",
"sonarjs/function-return-type": "off",

// React
"react/jsx-uses-react": 2,
"react/react-in-jsx-scope": 0,
Expand Down Expand Up @@ -183,7 +193,8 @@ export default [
},
],
"@typescript-eslint/no-shadow": [
2, {
2,
{
builtinGlobals: false,
hoist: "all",
},
Expand Down Expand Up @@ -215,6 +226,7 @@ export default [
"@typescript-eslint/block-spacing": 0,
"@typescript-eslint/quotes": 0,
"@typescript-eslint/use-unknown-in-catch-callback-variable": 0,
"@typescript-eslint/require-array-sort-compare": [2, {ignoreStringArrays: false}],
// TODO: enable this
"@typescript-eslint/prefer-readonly-parameter-types": 0,
// "@typescript-eslint/prefer-readonly-parameter-types": [
Expand Down Expand Up @@ -349,8 +361,8 @@ export default [
"coverage/*",

// Style's d.ts
// eslint-disable-next-line arrow-body-style, @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/explicit-function-return-type, @typescript-eslint/no-unsafe-argument
pathToFile => /\S+\.s?css\.d\.ts/u.test(pathToFile),
// eslint-disable-next-line arrow-body-style, @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/explicit-function-return-type, @typescript-eslint/no-unsafe-argument, sonarjs/slow-regex
pathToFile => /\S+\.s?css\.d\.ts$/u.test(pathToFile),

// Test
"test-backstop/*",
Expand Down
70 changes: 35 additions & 35 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,28 +74,28 @@
"clean-install-windows": "rd .\\node_modules\\ -r; npm i"
},
"devDependencies": {
"@babel/core": "^7.24.7",
"@babel/core": "^7.25.2",
"@babel/plugin-transform-strict-mode": "^7.24.7",
"@eslint/js": "^9.6.0",
"@storybook/addon-actions": "^8.1.11",
"@storybook/addon-essentials": "^8.1.11",
"@storybook/addon-interactions": "^8.1.11",
"@storybook/addon-links": "^8.1.11",
"@storybook/blocks": "^8.1.11",
"@storybook/builder-webpack5": "^8.1.11",
"@eslint/js": "^9.11.0",
"@storybook/addon-actions": "^8.3.2",
"@storybook/addon-essentials": "^8.3.2",
"@storybook/addon-interactions": "^8.3.2",
"@storybook/addon-links": "^8.3.2",
"@storybook/blocks": "^8.3.2",
"@storybook/builder-webpack5": "^8.3.2",
"@storybook/manager-webpack5": "^6.5.16",
"@storybook/react": "^8.1.11",
"@storybook/react-webpack5": "^8.1.11",
"@storybook/react": "^8.3.2",
"@storybook/react-webpack5": "^8.3.2",
"@storybook/testing-library": "^0.2.2",
"@testing-library/react": "^16.0.0",
"@testing-library/react": "^16.0.1",
"@types/circular-dependency-plugin": "^5.0.8",
"@types/duplicate-package-checker-webpack-plugin": "^2.1.5",
"@types/script-ext-html-webpack-plugin": "^2.1.6",
"@types/webpack-bundle-analyzer": "^4.7.0",
"@types/webpack-node-externals": "^3.0.4",
"ajv": "^8.16.0",
"babel-loader": "^9.1.3",
"backstopjs": "^6.3.23",
"ajv": "^8.17.1",
"babel-loader": "^9.2.1",
"backstopjs": "^6.3.25",
"circular-dependency-plugin": "^5.2.2",
"clean-webpack-plugin": "^4.0.0",
"copy-webpack-plugin": "^12.0.2",
Expand All @@ -104,47 +104,47 @@
"css-minimizer-webpack-plugin": "^7.0.0",
"css-module-typescript-loader": "^0.0.4",
"duplicate-package-checker-webpack-plugin": "^3.0.0",
"eslint": "^9.6.0",
"eslint": "^9.11.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-jest": "^28.6.0",
"eslint-plugin-jsx-a11y": "^6.9.0",
"eslint-plugin-react": "^7.34.3",
"eslint-plugin-jest": "^28.8.3",
"eslint-plugin-jsx-a11y": "^6.10.0",
"eslint-plugin-react": "^7.36.1",
"eslint-plugin-react-hooks": "^5.1.0-rc.0",
"eslint-plugin-simple-import-sort": "^12.1.1",
"eslint-plugin-sonarjs": "^1.0.3",
"eslint-plugin-unicorn": "^54.0.0",
"eslint-plugin-sonarjs": "^2.0.2",
"eslint-plugin-unicorn": "^55.0.0",
"html-webpack-plugin": "^5.6.0",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"jest-transform-stub": "^2.0.0",
"lighthouse": "^12.1.0",
"mini-css-extract-plugin": "^2.9.0",
"nodemon": "^3.1.4",
"lighthouse": "^12.2.1",
"mini-css-extract-plugin": "^2.9.1",
"nodemon": "^3.1.7",
"npm-watch": "^0.13.0",
"prettier": "^3.3.2",
"puppeteer": "^22.12.1",
"prettier": "^3.3.3",
"puppeteer": "^23.4.0",
"raw-loader": "^4.0.2",
"sass": "^1.77.6",
"sass-loader": "^14.2.1",
"sass": "^1.79.3",
"sass-loader": "^16.0.2",
"script-ext-html-webpack-plugin": "^2.1.5",
"storybook": "^8.1.11",
"storybook": "^8.3.2",
"style-loader": "^4.0.0",
"stylelint": "^16.6.1",
"stylelint": "^16.9.0",
"stylelint-config-standard": "^36.0.1",
"stylelint-config-standard-scss": "^13.1.0",
"stylelint-order": "^6.0.4",
"stylelint-scss": "^6.3.2",
"stylelint-scss": "^6.7.0",
"terser-webpack-plugin": "^5.3.10",
"ts-jest": "^29.1.5",
"ts-jest": "^29.2.5",
"ts-loader": "^9.5.1",
"ts-node": "^10.9.2",
"typescript": "^5.5.3",
"typescript": "^5.6.2",
"typescript-coverage-report": "^1.0.0",
"typescript-eslint": "^7.15.0",
"webpack": "^5.92.1",
"typescript-eslint": "^8.6.0",
"webpack": "^5.94.0",
"webpack-bundle-analyzer": "^4.10.2",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^5.0.4",
"webpack-dev-server": "^5.1.0",
"webpack-node-externals": "^3.0.0"
}
}
6 changes: 6 additions & 0 deletions tsconfig.eslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"allowJs": true
}
}
2 changes: 1 addition & 1 deletion webpack/setting/module/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {cwd} from "node:process";
import MiniCssExtractPlugin from "mini-css-extract-plugin";
import type {RuleSetRule} from "webpack";

import {fileRegExp,isDevelopment, isProduction, isTsTranspileOnly} from "../../config";
import {fileRegExp, isDevelopment, isProduction, isTsTranspileOnly} from "../../config";

const styleLoader = {
loader: "style-loader",
Expand Down
2 changes: 1 addition & 1 deletion webpack/setting/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
type WebpackPluginInstance,
} from "webpack";

import {isBuildLibrary,isDevelopment, isProduction} from "../config";
import {isBuildLibrary, isDevelopment, isProduction} from "../config";

const filePathPrefix = isProduction ? "./../" : "./";

Expand Down
2 changes: 1 addition & 1 deletion webpack/setting/resolve/alias.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from "node:path";
import {cwd} from "node:process";

import {isFront,isProduction} from "../../config";
import {isFront, isProduction} from "../../config";

const duplicateList = ["rc-resize-observer", "isarray", "@segment/isodate", "component-type", "uuid", "ms", "debug"];

Expand Down
2 changes: 1 addition & 1 deletion www/library/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import "./src/markdown.scss";

import {defaultMarkdownConfig, type ThemeNameEnum} from "./src/markdown-const";

export {markdown as default,markdown} from "./src/markdown";
export {markdown as default, markdown} from "./src/markdown";
export {defaultMarkdownConfig, ThemeNameEnum} from "./src/markdown-const";

export const classNameMdProThemeDark = "md-pro-theme-dark";
Expand Down
2 changes: 1 addition & 1 deletion www/library/src/helper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {MarkdownConfigType} from "../library";
import {defaultMarkdownConfig,themeClassNameMap} from "./markdown-const";
import {defaultMarkdownConfig, themeClassNameMap} from "./markdown-const";

export function getFullWrapperClassName(markdownConfig: MarkdownConfigType): string {
const {wrapperClassName: wrapperClassNameConfig, themeName} = markdownConfig;
Expand Down
3 changes: 2 additions & 1 deletion www/library/src/parser/footnote/footnote.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {DocumentMetaType, FootnoteType,LineDataType} from "../parser-type";
import type {DocumentMetaType, FootnoteType, LineDataType} from "../parser-type";
import {findFootnoteMarkGlobalRegExp, footnoteTypeMap} from "./footnote-const";
import {getFootnoteById, getFootnoteInlineLineContent, getFootnoteMarkId} from "./footnote-helper";

Expand All @@ -24,6 +24,7 @@ function matchToFootnote(match: string): FootnoteType {
}

export function getFootnoteList(lineContent: string): Array<FootnoteType> {
// eslint-disable-next-line sonarjs/sonar-prefer-regexp-exec
const matchedList = lineContent.match(findFootnoteMarkGlobalRegExp);

if (!matchedList) {
Expand Down
2 changes: 1 addition & 1 deletion www/library/src/parser/parse-line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function getShortInfo(trimmedLine: string): ShortLineInfoType {
};
}

// eslint-disable-next-line complexity, max-params, max-statements, @typescript-eslint/max-params
// eslint-disable-next-line complexity, max-params, max-statements, @typescript-eslint/max-params, sonarjs/cognitive-complexity
export function parseLine(
line: string,
lineIndex: number,
Expand Down
2 changes: 2 additions & 0 deletions www/library/src/parser/util/is-tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ export function getIsBlockquote(lineData: LineDataType): boolean {
return selectorBlockquoteList.includes(lineData.selector);
}

// eslint-disable-next-line sonarjs/slow-regex
const htmlPairTag = /<(\w+)[^>]*>[\S\s]*?<\/\1>/u;
// eslint-disable-next-line sonarjs/slow-regex
const htmlSingleTag = /<\w+[^>]*?\s*\/>/u;

export function getIsStartWithHtml(lineData: LineDataType): boolean {
Expand Down
1 change: 1 addition & 0 deletions www/library/src/parser/util/variable.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type {VariableType} from "../parser-type";

export function getVariableData(lineContent: string): VariableType | null {
// eslint-disable-next-line sonarjs/slow-regex
const matchData = /\[([^^][\S\s]+?)\]:\s+?\S/u.exec(lineContent);

if (!matchData) {
Expand Down
4 changes: 4 additions & 0 deletions www/library/src/render/render-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {breakLineTag, emptyString, space} from "./render-const";
import {makeLinkFromText, makeMailFromText} from "./render-link";
import {makePairTag} from "./render-pair-tag";

// eslint-disable-next-line sonarjs/slow-regex
export const breakLineRegExp = /\s*?\\$/u;

export function addBreakLine(line: string): string {
Expand Down Expand Up @@ -74,8 +75,11 @@ export function isImageListOnly(lineContent: string): boolean {
return lineContent.replace(findImageRegExpGlobal, "").trim() === emptyString;
}

// eslint-disable-next-line sonarjs/slow-regex
const findMailRegExpGlobal = /\[([\S\s]*?)\]\((\S+?)(?:\s+"([\S\s]+?)")?(?:\s+"([\S\s]+?)")?\)/gu;
// eslint-disable-next-line sonarjs/slow-regex
const findLinkRegExpGlobal = /\[([\S\s]*?)\]\((\S+?)(?:\s+"([\S\s]+?)")?\)/gu;
// eslint-disable-next-line sonarjs/slow-regex
const findLinkVariableRegExpGlobal = /\[([\S\s]*?)\]\[([\S\s]+?)\]/gu;

// eslint-disable-next-line @typescript-eslint/max-params
Expand Down
2 changes: 2 additions & 0 deletions www/library/src/render/render-link.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import {mailPrefix} from "../markdown-const";
import {getLinkIndexList, getTagIndexList, harArrayListOverflow, type PairNumberArrayType} from "./render-util";

// eslint-disable-next-line sonarjs/slow-regex
const linkTextRegExpGlobal = /(\w+:\/\/[\w.]+\.\w+[\w+/]*)/giu;
// eslint-disable-next-line sonarjs/slow-regex
const mailTextRegExpGlobal = /([\w.-]+@[\w.]+\.\w+[\w+/]*)/giu;

function linkReplacer(html: string, replacer: Readonly<RegExp>, hrefPrefix: string): string {
Expand Down
1 change: 1 addition & 0 deletions www/library/src/render/render-pair-tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export function getSelectorIndexList(html: string, pairTagSelector: PairTagSelec
let indexOfSelector: number = html.indexOf(selector, 0);

while (indexOfSelector !== -1) {
// eslint-disable-next-line sonarjs/sonar-prefer-regexp-exec
const equalSymbolsMatch: Array<string> | null = html.slice(indexOfSelector).match(equal);

if (!equalSymbolsMatch) {
Expand Down
3 changes: 3 additions & 0 deletions www/library/src/render/render-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export function harArrayListOverflow(
function getMatchIndexList(html: string, regExp: RegExp): Array<PairNumberArrayType> {
const resultList: Array<PairNumberArrayType> = [];

// eslint-disable-next-line sonarjs/sonar-prefer-regexp-exec
const matchList = html.match(regExp);

if (!matchList) {
Expand All @@ -43,12 +44,14 @@ function getMatchIndexList(html: string, regExp: RegExp): Array<PairNumberArrayT
return resultList;
}

// eslint-disable-next-line sonarjs/slow-regex
const tagSelectorRegExpGlobal = /(<\w+[\S\s]*?>)|(<\/\w+?>)|(<\w+[\S\s]*?\/>)/gu;

export function getTagIndexList(html: string): Array<PairNumberArrayType> {
return getMatchIndexList(html, tagSelectorRegExpGlobal);
}

// eslint-disable-next-line sonarjs/slow-regex
const linkSelectorRegExpGlobal = /(<a\s*?>[\S\s]*?<\/a>)|(<a\s[\S\s]*?>[\S\s]*?<\/a>)|(<a\s+[\S\s]*?\/>)/gu;

export function getLinkIndexList(html: string): Array<PairNumberArrayType> {
Expand Down
2 changes: 1 addition & 1 deletion www/library/src/render/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function renderChildList(lineDataList: Array<LineDataType>, documentMeta:
.join(emptyString);
}

// eslint-disable-next-line max-statements, @typescript-eslint/max-params
// eslint-disable-next-line max-statements, @typescript-eslint/max-params, sonarjs/cognitive-complexity
export function renderLineData(
lineData: LineDataType,
lineDataIndex: number,
Expand Down
3 changes: 2 additions & 1 deletion www/library/src/test/config.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import {describe, expect,it} from "@jest/globals";
import {describe, expect, it} from "@jest/globals";

import {defaultMarkdownConfig, markdown, ThemeNameEnum} from "../../library";
import {themeClassNameMap} from "../markdown-const";

describe("markdown-pro test:config", () => {
it("additional css class", () => {
expect.assertions(2);

const additionalCssClass = "additional-css-class";

expect(markdown("", {wrapperClassName: additionalCssClass})).toContain(additionalCssClass);
Expand Down
Loading

0 comments on commit 2adc9c6

Please sign in to comment.