From 6d501938efdcd0fdd7d84e4e26d06cc4a76ecca9 Mon Sep 17 00:00:00 2001
From: fraxken
Date: Tue, 13 Aug 2024 00:32:45 +0200
Subject: [PATCH 1/5] fix(docs): missing closing balise
---
src/eslint/README.md | 6 ++---
src/typescript/README.md | 49 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 52 insertions(+), 3 deletions(-)
create mode 100644 src/typescript/README.md
diff --git a/src/eslint/README.md b/src/eslint/README.md
index 1ec2607..5a44b17 100644
--- a/src/eslint/README.md
+++ b/src/eslint/README.md
@@ -1,6 +1,6 @@
-
- Eslint Config
-
+
+
Eslint Config
+
OpenAlly Node.js Eslint configuration (Work for both JavaScript and TypeScript projects).
diff --git a/src/typescript/README.md b/src/typescript/README.md
new file mode 100644
index 0000000..54e0b98
--- /dev/null
+++ b/src/typescript/README.md
@@ -0,0 +1,49 @@
+
+
TypeScript Config
+
+
+OpenAlly TypeScript CJS & ESM configurations.
+
+## Getting Started
+
+This package is available in the Node Package Repository and can be easily installed with [npm](https://docs.npmjs.com/getting-started/what-is-npm) or [yarn](https://yarnpkg.com).
+
+```bash
+$ npm i -D @openally/config.typescript
+# or
+$ yarn add @openally/config.typescript -D
+```
+
+## Usage
+
+```json
+{
+ "extends": "@openally/config.typescript/cjs",
+ "compilerOptions": {
+ "outDir": "dist",
+ "rootDir": "./src"
+ },
+ "include": ["src"],
+ "exclude": ["node_modules", "dist"]
+}
+
+```
+
+Use either **cjs** or **esm**
+
+```json
+{
+ "exports": {
+ "./esm": "./src/esm/tsconfig.json",
+ "./cjs": "./src/cjs/tsconfig.json"
+ }
+}
+```
+
+> [!NOTE]
+> The original inspiration for those configurations is [The TSConfig Cheat Sheet
+](https://www.totaltypescript.com/tsconfig-cheat-sheet) by Matt Pocock.
+
+
+## License
+MIT
From 4fc2d47bbb4c29803a16f192971761a0d6f0eaa5 Mon Sep 17 00:00:00 2001
From: fraxken
Date: Tue, 13 Aug 2024 00:23:55 +0200
Subject: [PATCH 2/5] feat: implement typescript configs V1.0
chore: complete configs with more keys
---
src/eslint/package.json | 1 +
src/eslint/src/index.ts | 5 ++--
src/eslint/tsconfig.json | 15 ++----------
src/typescript/cjs/tsconfig.json | 34 ++++++++++++++++++++++++++
src/typescript/{ => esm}/tsconfig.json | 16 +++++++-----
src/typescript/package.json | 3 ++-
6 files changed, 52 insertions(+), 22 deletions(-)
create mode 100644 src/typescript/cjs/tsconfig.json
rename src/typescript/{ => esm}/tsconfig.json (69%)
diff --git a/src/eslint/package.json b/src/eslint/package.json
index 8d56614..c10a32e 100644
--- a/src/eslint/package.json
+++ b/src/eslint/package.json
@@ -2,6 +2,7 @@
"name": "@openally/config.eslint",
"version": "1.0.0",
"description": "OpenAlly ESLint configuration for Node.js and TypeScript",
+ "type": "module",
"main": "./dist/index.js",
"scripts": {
"build": "tsc",
diff --git a/src/eslint/src/index.ts b/src/eslint/src/index.ts
index e496c53..4e913cf 100644
--- a/src/eslint/src/index.ts
+++ b/src/eslint/src/index.ts
@@ -1,9 +1,9 @@
// Import Third-party Dependencies
import stylisticPlugin from "@stylistic/eslint-plugin";
import globals from "globals";
-import tsEslint, { ConfigWithExtends } from "typescript-eslint";
+import tsEslint, { type ConfigWithExtends } from "typescript-eslint";
import * as tsParser from "@typescript-eslint/parser";
-import { SourceType } from "@typescript-eslint/types";
+import type { SourceType } from "@typescript-eslint/types";
// Import Internal Dependencies
import bestPractices from "./rules/best-practices.js";
@@ -38,6 +38,7 @@ const kRules: Record = {
const kBaseTypeScriptConfigs: ConfigWithExtends[] = [
{
plugins: {
+ // @ts-ignore
"@stylistic": stylisticPlugin
},
rules: {
diff --git a/src/eslint/tsconfig.json b/src/eslint/tsconfig.json
index de4ebfc..2bf942d 100644
--- a/src/eslint/tsconfig.json
+++ b/src/eslint/tsconfig.json
@@ -1,19 +1,8 @@
{
+ "extends": "../typescript/esm/tsconfig.json",
"compilerOptions": {
- "declaration": true,
- "strictNullChecks": true,
- "target": "ES2022",
"outDir": "dist",
- "module": "NodeNext",
- "moduleResolution": "NodeNext",
- "esModuleInterop": true,
- "resolveJsonModule": false,
- "skipDefaultLibCheck": true,
- "skipLibCheck": true,
- "forceConsistentCasingInFileNames": true,
- "sourceMap": true,
- "rootDir": "./src",
- "types": ["node"]
+ "rootDir": "./src"
},
"include": ["src"],
"exclude": ["node_modules", "dist"]
diff --git a/src/typescript/cjs/tsconfig.json b/src/typescript/cjs/tsconfig.json
new file mode 100644
index 0000000..c541cad
--- /dev/null
+++ b/src/typescript/cjs/tsconfig.json
@@ -0,0 +1,34 @@
+{
+ "compilerOptions": {
+ /* Base Options: */
+ "esModuleInterop": true,
+ "skipLibCheck": true,
+ "target": "es2022",
+ "allowJs": true,
+ "resolveJsonModule": true,
+ "moduleDetection": "force",
+ "isolatedModules": true,
+ "verbatimModuleSyntax": false,
+
+ /* Strictness */
+ "strict": true,
+ "strictNullChecks": true,
+ "noUncheckedIndexedAccess": false,
+ "noImplicitAny": false,
+ "noImplicitOverride": true,
+ "noImplicitThis": true,
+ "noImplicitReturns": true,
+ "noUnusedLocals": true,
+ "forceConsistentCasingInFileNames": true,
+
+ /* Others */
+ "module": "CommonJS",
+ "moduleResolution": "Node",
+ "sourceMap": true,
+ "declaration": true,
+ "composite": false,
+ "declarationMap": true,
+ "experimentalDecorators": true,
+ "lib": ["es2022"]
+ }
+}
diff --git a/src/typescript/tsconfig.json b/src/typescript/esm/tsconfig.json
similarity index 69%
rename from src/typescript/tsconfig.json
rename to src/typescript/esm/tsconfig.json
index ef919fc..fafbc2b 100644
--- a/src/typescript/tsconfig.json
+++ b/src/typescript/esm/tsconfig.json
@@ -9,11 +9,17 @@
"moduleDetection": "force",
"isolatedModules": true,
"verbatimModuleSyntax": true,
-
+
/* Strictness */
"strict": true,
+ "strictNullChecks": true,
"noUncheckedIndexedAccess": false,
+ "noImplicitAny": false,
"noImplicitOverride": true,
+ "noImplicitThis": true,
+ "noImplicitReturns": true,
+ "noUnusedLocals": true,
+ "forceConsistentCasingInFileNames": true,
/* Others */
"module": "NodeNext",
@@ -21,9 +27,7 @@
"declaration": true,
"composite": false,
"declarationMap": true,
+ "experimentalDecorators": true,
"lib": ["es2022"]
- },
- "exclude": [
- "node_modules"
- ]
-}
\ No newline at end of file
+ }
+}
diff --git a/src/typescript/package.json b/src/typescript/package.json
index b5d7d4e..d860000 100644
--- a/src/typescript/package.json
+++ b/src/typescript/package.json
@@ -3,7 +3,8 @@
"version": "1.0.0",
"description": "TypeScript configuration (TSConfig)",
"exports": {
- "./tsconfig": "./src/tsconfig.json"
+ "./esm": "./src/esm/tsconfig.json",
+ "./cjs": "./src/cjs/tsconfig.json"
},
"files": [
"src"
From e577fe201a401e926d7a59a8596aace227868822 Mon Sep 17 00:00:00 2001
From: fraxken
Date: Tue, 13 Aug 2024 01:13:16 +0200
Subject: [PATCH 3/5] refactor(eslint): enhance sync script
---
package-lock.json | 71 +++++++++++++++++
src/eslint/package.json | 4 +-
src/eslint/scripts/sync.ts | 86 ++++++++++++++++++++
src/eslint/src/index.ts | 23 +-----
src/eslint/src/rules/best-practices.ts | 3 +-
src/eslint/src/rules/ecmascript6.ts | 4 +-
src/eslint/src/rules/eslintv9.ts | 3 +-
src/eslint/src/rules/index.ts | 23 ++++++
src/eslint/src/rules/possible-errors.ts | 3 +-
src/eslint/src/rules/styles.ts | 3 +-
src/eslint/src/rules/stylistic.ts | 3 +-
src/eslint/src/rules/typescript.ts | 3 +-
src/eslint/src/rules/variables.ts | 3 +-
src/eslint/tools/sync.ts | 100 ------------------------
tsconfig.json | 3 -
15 files changed, 194 insertions(+), 141 deletions(-)
create mode 100644 src/eslint/scripts/sync.ts
create mode 100644 src/eslint/src/rules/index.ts
delete mode 100644 src/eslint/tools/sync.ts
diff --git a/package-lock.json b/package-lock.json
index 1543de0..24d381a 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -692,6 +692,22 @@
"@jridgewell/sourcemap-codec": "^1.4.14"
}
},
+ "node_modules/@myunisoft/httpie": {
+ "version": "5.0.0",
+ "resolved": "https://registry.npmjs.org/@myunisoft/httpie/-/httpie-5.0.0.tgz",
+ "integrity": "sha512-U4C1PA5lYPAYXZDAQvlKy35wWnZfAR9HN8Sn/xaZYxO2jK/MMfZRzak/c0FzmxNUhroCeMmfiN0JTjChKBl+mA==",
+ "dev": true,
+ "dependencies": {
+ "@openally/result": "^1.2.1",
+ "content-type": "^1.0.5",
+ "lru-cache": "^10.1.0",
+ "statuses": "^2.0.1",
+ "undici": "^6.9.0"
+ },
+ "engines": {
+ "node": ">=20"
+ }
+ },
"node_modules/@nodelib/fs.scandir": {
"version": "2.1.5",
"resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz",
@@ -735,6 +751,15 @@
"resolved": "src/typescript",
"link": true
},
+ "node_modules/@openally/result": {
+ "version": "1.3.0",
+ "resolved": "https://registry.npmjs.org/@openally/result/-/result-1.3.0.tgz",
+ "integrity": "sha512-4S/bXxD04aKwKPte7gDkyvbyEF8rP7fTQkzwoHMC7C8mu+XUnn2L+YIq2aGtW3GNo3O+3n51SoqiMTcmkKiC7Q==",
+ "dev": true,
+ "engines": {
+ "node": ">=16.9.x"
+ }
+ },
"node_modules/@pkgjs/parseargs": {
"version": "0.11.0",
"resolved": "https://registry.npmjs.org/@pkgjs/parseargs/-/parseargs-0.11.0.tgz",
@@ -854,6 +879,17 @@
"dev": true,
"license": "MIT"
},
+ "node_modules/@types/jsdom": {
+ "version": "21.1.7",
+ "resolved": "https://registry.npmjs.org/@types/jsdom/-/jsdom-21.1.7.tgz",
+ "integrity": "sha512-yOriVnggzrnQ3a9OKOCxaVuSug3w3/SbOj5i7VwXWZEyUNl3bLF9V3MfxGbZKuwqJOQyRfqXyROBB1CoZLFWzA==",
+ "dev": true,
+ "dependencies": {
+ "@types/node": "*",
+ "@types/tough-cookie": "*",
+ "parse5": "^7.0.0"
+ }
+ },
"node_modules/@types/json-schema": {
"version": "7.0.15",
"resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz",
@@ -870,6 +906,12 @@
"undici-types": "~6.13.0"
}
},
+ "node_modules/@types/tough-cookie": {
+ "version": "4.0.5",
+ "resolved": "https://registry.npmjs.org/@types/tough-cookie/-/tough-cookie-4.0.5.tgz",
+ "integrity": "sha512-/Ad8+nIOV7Rl++6f1BdKxFSMgmoqEoYbHRpPcx3JEfv8VRsQe9Z4mCXeJBzxs7mbHY/XOZZuXlRNfhpVPbs6ZA==",
+ "dev": true
+ },
"node_modules/@typescript-eslint/eslint-plugin": {
"version": "8.1.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.1.0.tgz",
@@ -1338,6 +1380,15 @@
"integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==",
"license": "MIT"
},
+ "node_modules/content-type": {
+ "version": "1.0.5",
+ "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz",
+ "integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==",
+ "dev": true,
+ "engines": {
+ "node": ">= 0.6"
+ }
+ },
"node_modules/convert-source-map": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-2.0.0.tgz",
@@ -2754,6 +2805,15 @@
"node": ">=8"
}
},
+ "node_modules/statuses": {
+ "version": "2.0.1",
+ "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz",
+ "integrity": "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==",
+ "dev": true,
+ "engines": {
+ "node": ">= 0.8"
+ }
+ },
"node_modules/string-width": {
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-5.1.2.tgz",
@@ -3023,6 +3083,15 @@
}
}
},
+ "node_modules/undici": {
+ "version": "6.19.7",
+ "resolved": "https://registry.npmjs.org/undici/-/undici-6.19.7.tgz",
+ "integrity": "sha512-HR3W/bMGPSr90i8AAp2C4DM3wChFdJPLrWYpIS++LxS8K+W535qftjt+4MyjNYHeWabMj1nvtmLIi7l++iq91A==",
+ "dev": true,
+ "engines": {
+ "node": ">=18.17"
+ }
+ },
"node_modules/undici-types": {
"version": "6.13.0",
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.13.0.tgz",
@@ -3384,6 +3453,8 @@
"typescript-eslint": "^8.1.0"
},
"devDependencies": {
+ "@myunisoft/httpie": "^5.0.0",
+ "@types/jsdom": "^21.1.7",
"@typescript-eslint/types": "^8.1.0",
"jsdom": "^24.1.1"
}
diff --git a/src/eslint/package.json b/src/eslint/package.json
index c10a32e..270901e 100644
--- a/src/eslint/package.json
+++ b/src/eslint/package.json
@@ -10,7 +10,7 @@
"test-only": "tsx --test ./test/test.ts",
"test": "c8 --all --src ./src -r html npm run test-only",
"lint": "cross-env eslint src/**/*.ts",
- "sync": "npx tsx ./tools/sync.ts"
+ "sync": "npx tsx ./scripts/sync.ts"
},
"files": [
"dist"
@@ -30,6 +30,8 @@
"typescript-eslint": "^8.1.0"
},
"devDependencies": {
+ "@myunisoft/httpie": "^5.0.0",
+ "@types/jsdom": "^21.1.7",
"@typescript-eslint/types": "^8.1.0",
"jsdom": "^24.1.1"
}
diff --git a/src/eslint/scripts/sync.ts b/src/eslint/scripts/sync.ts
new file mode 100644
index 0000000..8f6f200
--- /dev/null
+++ b/src/eslint/scripts/sync.ts
@@ -0,0 +1,86 @@
+// Import Third-party Dependencies
+import { request } from "@myunisoft/httpie";
+import { JSDOM } from "jsdom";
+
+// Import Internal Dependencies
+import { rulesWithTS } from "../src/rules/index.js";
+
+// CONSTANTS
+const kEslintRulesReferenceUrl = "https://eslint.org/docs/latest/rules/";
+const kStylisticRulesUrl = "https://eslint.style/rules";
+const kLocalRules = new Set(Object.keys(rulesWithTS));
+
+const [eslintResult, stylisticResult] = await Promise.all([
+ request("GET", kEslintRulesReferenceUrl),
+ request("GET", kStylisticRulesUrl)
+]);
+const eslintDom = new JSDOM(eslintResult.data);
+const stylisticDom = new JSDOM(stylisticResult.data);
+const rules = new Set([
+ ...parseESLintRulesReferences(eslintDom),
+ ...parseStylisticRules(stylisticDom)
+]);
+
+for (const rule of rules) {
+ if (kLocalRules.has(rule.ruleName) && rule.isDeprecated) {
+ console.error(
+ `Rule "${rule.ruleName}" is deprecated! (https://eslint.org/docs/latest/rules/${rule.ruleName})`
+ );
+ }
+ else if (kLocalRules.has(rule.ruleName) && rule.isRemoved) {
+ console.error(
+ `Rule "${rule.ruleName}" is removed! (https://eslint.org/docs/latest/rules/${rule.ruleName})`
+ );
+ }
+ else if (
+ !kLocalRules.has(rule.ruleName) &&
+ !kLocalRules.has(`@stylistic/${rule.ruleName}`) &&
+ !rule.isDeprecated &&
+ !rule.isRemoved
+ ) {
+ const label = kEslintRulesReferenceUrl + rule.ruleName;
+ console.error(
+ `Rule "${rule.ruleName}" is not present in the local ESLint configuration!(${label})`
+ );
+ }
+}
+console.log("Done!");
+
+function parseESLintRulesReferences(
+ dom: JSDOM
+) {
+ return [
+ ...dom.window.document.querySelectorAll("article.rule")
+ ].map((rule) => {
+ return {
+ ruleName: parseRuleName(rule.textContent),
+ isDeprecated: rule.classList.contains("rule--deprecated"),
+ isRemoved: rule.classList.contains("rule--removed")
+ };
+ });
+}
+
+function parseStylisticRules(
+ dom: JSDOM
+) {
+ return [
+ ...dom.window.document.querySelectorAll("td a code")
+ ].map((rule) => {
+ return {
+ ruleName: parseRuleName(rule.textContent),
+ isDeprecated: false,
+ isRemoved: false
+ };
+ });
+}
+
+function parseRuleName(textContent: string | null) {
+ if (typeof textContent === "string") {
+ return textContent
+ .replace(/\n/g, " ")
+ .trimStart()
+ .split(" ")[0];
+ }
+
+ return "";
+}
diff --git a/src/eslint/src/index.ts b/src/eslint/src/index.ts
index 4e913cf..cbfe4bb 100644
--- a/src/eslint/src/index.ts
+++ b/src/eslint/src/index.ts
@@ -6,14 +6,7 @@ import * as tsParser from "@typescript-eslint/parser";
import type { SourceType } from "@typescript-eslint/types";
// Import Internal Dependencies
-import bestPractices from "./rules/best-practices.js";
-import ecmascript6 from "./rules/ecmascript6.js";
-import eslintv9 from "./rules/eslintv9.js";
-import possibleErrors from "./rules/possible-errors.js";
-import styles from "./rules/styles.js";
-import variables from "./rules/variables.js";
-import stylistic from "./rules/stylistic.js";
-import typescript from "./rules/typescript.js";
+import { rules, rulesWithTS } from "./rules/index.js";
const kLanguageOptions = {
sourceType: "script",
@@ -26,15 +19,6 @@ const kTypescriptLanguageOptions = {
sourceType: "module" as SourceType,
parser: tsParser
};
-const kRules: Record = {
- ...bestPractices,
- ...possibleErrors,
- ...styles,
- ...ecmascript6,
- ...eslintv9,
- ...variables,
- ...stylistic
-};
const kBaseTypeScriptConfigs: ConfigWithExtends[] = [
{
plugins: {
@@ -42,8 +26,7 @@ const kBaseTypeScriptConfigs: ConfigWithExtends[] = [
"@stylistic": stylisticPlugin
},
rules: {
- ...kRules,
- ...typescript as any,
+ ...rulesWithTS,
"no-undef": "off",
"no-redeclare": "off"
},
@@ -62,7 +45,7 @@ export const ESLintConfig = [{
plugins: {
"@stylistic": stylisticPlugin
},
- rules: kRules,
+ rules,
languageOptions: kLanguageOptions
}];
diff --git a/src/eslint/src/rules/best-practices.ts b/src/eslint/src/rules/best-practices.ts
index f8e41ae..15d3bbc 100644
--- a/src/eslint/src/rules/best-practices.ts
+++ b/src/eslint/src/rules/best-practices.ts
@@ -1,4 +1,4 @@
-const rules = {
+export default {
// See: https://eslint.org/docs/rules/accessor-pairs
"accessor-pairs": "off",
@@ -215,4 +215,3 @@ const rules = {
// See: https://eslint.org/docs/rules/yoda
yoda: "error"
};
-export default rules;
diff --git a/src/eslint/src/rules/ecmascript6.ts b/src/eslint/src/rules/ecmascript6.ts
index d5f6fb1..4d50757 100644
--- a/src/eslint/src/rules/ecmascript6.ts
+++ b/src/eslint/src/rules/ecmascript6.ts
@@ -1,4 +1,4 @@
-const rules = {
+export default {
// See: https://eslint.org/docs/rules/arrow-body-style
"arrow-body-style": ["error", "as-needed", { requireReturnForObjectLiteral: true }],
@@ -89,5 +89,3 @@ const rules = {
// See: https://eslint.style/rules/js/ryield-star-spacing
"@stylistic/yield-star-spacing": ["error", { before: false, after: true }]
};
-
-export default rules;
diff --git a/src/eslint/src/rules/eslintv9.ts b/src/eslint/src/rules/eslintv9.ts
index 1e88e32..8697fc3 100644
--- a/src/eslint/src/rules/eslintv9.ts
+++ b/src/eslint/src/rules/eslintv9.ts
@@ -1,4 +1,4 @@
-const rules = {
+export default {
"no-constant-binary-expression": "error",
"no-constructor-return": "off",
"no-dupe-else-if": "error",
@@ -28,4 +28,3 @@ const rules = {
"prefer-regex-literals": "off",
strict: "off"
};
-export default rules;
diff --git a/src/eslint/src/rules/index.ts b/src/eslint/src/rules/index.ts
new file mode 100644
index 0000000..ebf4941
--- /dev/null
+++ b/src/eslint/src/rules/index.ts
@@ -0,0 +1,23 @@
+import possibleErrors from "./possible-errors.js";
+import bestPractices from "./best-practices.js";
+import ecmascript6 from "./ecmascript6.js";
+import styles from "./styles.js";
+import variables from "./variables.js";
+import eslintv9 from "./eslintv9.js";
+import typescript from "./typescript.js";
+import stylistic from "./stylistic.js";
+
+export const rules: Record = {
+ ...bestPractices,
+ ...possibleErrors,
+ ...styles,
+ ...ecmascript6,
+ ...eslintv9,
+ ...variables,
+ ...stylistic
+};
+
+export const rulesWithTS: Record = {
+ ...rules,
+ ...typescript
+};
diff --git a/src/eslint/src/rules/possible-errors.ts b/src/eslint/src/rules/possible-errors.ts
index b3de8ec..0c972ea 100644
--- a/src/eslint/src/rules/possible-errors.ts
+++ b/src/eslint/src/rules/possible-errors.ts
@@ -1,4 +1,4 @@
-const rules = {
+export default {
// See: https://eslint.org/docs/rules/for-direction
"for-direction": "error",
@@ -107,4 +107,3 @@ const rules = {
// See: https://eslint.org/docs/rules/valid-typeof
"valid-typeof": ["error", { requireStringLiterals: true }]
};
-export default rules;
diff --git a/src/eslint/src/rules/styles.ts b/src/eslint/src/rules/styles.ts
index fb0d097..be40f2f 100644
--- a/src/eslint/src/rules/styles.ts
+++ b/src/eslint/src/rules/styles.ts
@@ -1,4 +1,4 @@
-const rules = {
+export default {
// See: https://eslint.style/rules/js/array-bracket-newline
"@stylistic/array-bracket-newline": "off",
@@ -294,4 +294,3 @@ const rules = {
// See: https://eslint.style/rules/js/twrap-regex
"@stylistic/wrap-regex": "off"
};
-export default rules;
diff --git a/src/eslint/src/rules/stylistic.ts b/src/eslint/src/rules/stylistic.ts
index 459b848..3a46fda 100644
--- a/src/eslint/src/rules/stylistic.ts
+++ b/src/eslint/src/rules/stylistic.ts
@@ -1,4 +1,4 @@
-const rules = {
+export default {
// https://eslint.style/rules/js/function-call-argument-newline#consistent
"@stylistic/function-call-argument-newline": ["error", "consistent"],
// https://eslint.style/rules/js/function-call-spacing#never
@@ -34,4 +34,3 @@ const rules = {
"@stylistic/jsx-tag-spacing": "off",
"@stylistic/jsx-wrap-multilines": "off"
};
-export default rules;
diff --git a/src/eslint/src/rules/typescript.ts b/src/eslint/src/rules/typescript.ts
index 212230d..8869c72 100644
--- a/src/eslint/src/rules/typescript.ts
+++ b/src/eslint/src/rules/typescript.ts
@@ -1,7 +1,7 @@
/**
* See https://eslint.style/packages/ts#rules
*/
-const rules = {
+export default {
"@stylistic/brace-style": ["error", "stroustrup"],
"@stylistic/comma-dangle": ["error", "never"],
"@stylistic/comma-spacing": [
@@ -61,4 +61,3 @@ const rules = {
}
]
};
-export default rules;
diff --git a/src/eslint/src/rules/variables.ts b/src/eslint/src/rules/variables.ts
index c3b4eec..a3121db 100644
--- a/src/eslint/src/rules/variables.ts
+++ b/src/eslint/src/rules/variables.ts
@@ -1,4 +1,4 @@
-const rules = {
+export default {
// See: https://eslint.org/docs/rules/init-declarations
"init-declarations": "off",
@@ -29,4 +29,3 @@ const rules = {
// See: https://eslint.org/docs/rules/no-unused-vars
"no-unused-vars": "off"
};
-export default rules;
diff --git a/src/eslint/tools/sync.ts b/src/eslint/tools/sync.ts
deleted file mode 100644
index 3abb0bd..0000000
--- a/src/eslint/tools/sync.ts
+++ /dev/null
@@ -1,100 +0,0 @@
-// Import Third-party Dependencies
-import { request } from "@myunisoft/httpie";
-import { JSDOM } from "jsdom";
-
-// Import Internal Dependencies
-import possibleErrors from "../src/rules/possible-errors.js";
-import bestPractices from "../src/rules/best-practices.js";
-import ecmascript6 from "../src/rules/ecmascript6.js";
-import styles from "../src/rules/styles.js";
-import variables from "../src/rules/variables.js";
-import eslintv9 from "../src/rules/eslintv9.js";
-import typescript from "../src/rules/typescript.js";
-import stylistic from "../src/rules/stylistic.js";
-
-// CONSTANTS
-const kEslintRulesReferenceUrl = "https://eslint.org/docs/latest/rules/";
-const kStylisticRulesUrl = "https://eslint.style/rules";
-const kLocalRules = new Set([
- ...Object.keys(possibleErrors),
- ...Object.keys(bestPractices),
- ...Object.keys(ecmascript6),
- ...Object.keys(styles),
- ...Object.keys(variables),
- ...Object.keys(eslintv9),
- ...Object.keys(typescript),
- ...Object.keys(stylistic)
-]);
-
-async function main() {
- try {
- const eslintResult = await request("GET", kEslintRulesReferenceUrl);
- const eslintDom = new JSDOM(eslintResult.data as string);
- const stylisticResult = await request("GET", kStylisticRulesUrl);
- const stylisticDom = new JSDOM(stylisticResult.data as string);
- const rules = new Set([
- ...parseESLintRulesReferences(eslintDom),
- ...parseStylisticRules(stylisticDom)
- ]);
-
- for (const rule of rules) {
- if (kLocalRules.has(rule.ruleName) && rule.isDeprecated) {
- console.error(
- `Rule "${rule.ruleName}" is deprecated! (https://eslint.org/docs/latest/rules/${rule.ruleName})`
- );
- }
- else if (kLocalRules.has(rule.ruleName) && rule.isRemoved) {
- console.error(
- `Rule "${rule.ruleName}" is removed! (https://eslint.org/docs/latest/rules/${rule.ruleName})`
- );
- }
- else if (
- !kLocalRules.has(rule.ruleName) &&
- !kLocalRules.has(`@stylistic/${rule.ruleName}`) &&
- !rule.isDeprecated &&
- !rule.isRemoved
- ) {
- const label = kEslintRulesReferenceUrl + rule.ruleName;
- console.error(
- `Rule "${rule.ruleName}" is not present in the local ESLint configuration!(${label})`
- );
- }
- }
- }
- catch (error) {
- console.error(error);
- }
- console.log("Done!");
-}
-
-function* parseESLintRulesReferences(dom) {
- const rules = [...dom.window.document.querySelectorAll("article.rule")];
- for (const rule of rules) {
- const isDeprecated = rule.classList.contains("rule--deprecated");
- const isRemoved = rule.classList.contains("rule--removed");
- const ruleName = rule.textContent.replaceAll(/\n/g, " ").trimStart().split(" ")[0];
-
- yield {
- ruleName,
- isDeprecated,
- isRemoved
- };
- }
-}
-
-function* parseStylisticRules(dom) {
- const rules = [...dom.window.document.querySelectorAll("td a code")];
- for (const rule of rules) {
- const isDeprecated = false;
- const isRemoved = false;
- const ruleName = rule.textContent.replaceAll(/\n/g, " ").trimStart().split(" ")[0];
-
- yield {
- ruleName,
- isDeprecated,
- isRemoved
- };
- }
-}
-
-main();
diff --git a/tsconfig.json b/tsconfig.json
index 958e67c..337c321 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -1,9 +1,6 @@
{
"files": [],
"references": [
- {
- "path": "./src/typescript"
- },
{
"path": "./src/eslint"
}
From 3538b5bae816dade1a90dd3548435c4c87200350 Mon Sep 17 00:00:00 2001
From: fraxken
Date: Tue, 13 Aug 2024 01:19:16 +0200
Subject: [PATCH 4/5] chore(eslint): reformat index.ts
---
src/eslint/src/index.ts | 38 ++++++++++++++++++++------------------
1 file changed, 20 insertions(+), 18 deletions(-)
diff --git a/src/eslint/src/index.ts b/src/eslint/src/index.ts
index cbfe4bb..efd0fbf 100644
--- a/src/eslint/src/index.ts
+++ b/src/eslint/src/index.ts
@@ -14,11 +14,7 @@ const kLanguageOptions = {
...globals.node
}
};
-const kTypescriptLanguageOptions = {
- ...kLanguageOptions,
- sourceType: "module" as SourceType,
- parser: tsParser
-};
+
const kBaseTypeScriptConfigs: ConfigWithExtends[] = [
{
plugins: {
@@ -30,7 +26,11 @@ const kBaseTypeScriptConfigs: ConfigWithExtends[] = [
"no-undef": "off",
"no-redeclare": "off"
},
- languageOptions: kTypescriptLanguageOptions,
+ languageOptions: {
+ ...kLanguageOptions,
+ sourceType: "module" as SourceType,
+ parser: tsParser
+ },
files: ["**/*.ts"]
},
{
@@ -41,18 +41,20 @@ const kBaseTypeScriptConfigs: ConfigWithExtends[] = [
}
];
-export const ESLintConfig = [{
- plugins: {
- "@stylistic": stylisticPlugin
- },
- rules,
- languageOptions: kLanguageOptions
-}];
-
-export function typescriptConfig(config?: ConfigWithExtends) {
- if (config) {
- return tsEslint.config(...kBaseTypeScriptConfigs, config);
+export const ESLintConfig = [
+ {
+ plugins: {
+ "@stylistic": stylisticPlugin
+ },
+ rules,
+ languageOptions: kLanguageOptions
}
+];
- return tsEslint.config(...kBaseTypeScriptConfigs);
+export function typescriptConfig(
+ config?: ConfigWithExtends
+) {
+ return config ?
+ tsEslint.config(...kBaseTypeScriptConfigs, config) :
+ tsEslint.config(...kBaseTypeScriptConfigs);
}
From 395e4a153bd4453c301d8c8709eda6fcfd727969 Mon Sep 17 00:00:00 2001
From: fraxken
Date: Tue, 13 Aug 2024 01:25:05 +0200
Subject: [PATCH 5/5] chore(typescript): add default export
---
src/typescript/package.json | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/typescript/package.json b/src/typescript/package.json
index d860000..de47daa 100644
--- a/src/typescript/package.json
+++ b/src/typescript/package.json
@@ -3,6 +3,7 @@
"version": "1.0.0",
"description": "TypeScript configuration (TSConfig)",
"exports": {
+ ".": "./src/esm/tsconfig.json",
"./esm": "./src/esm/tsconfig.json",
"./cjs": "./src/cjs/tsconfig.json"
},