Skip to content

Commit

Permalink
feat(eslint-config): add many rules of eslint-plugin-unicorn
Browse files Browse the repository at this point in the history
  • Loading branch information
zanminkian committed Nov 28, 2024
1 parent 36d1fb0 commit 3f4e737
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/silent-radios-serve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fenge/eslint-config": patch
---

feat(eslint-config): add many rules of `eslint-plugin-unicorn`
23 changes: 23 additions & 0 deletions packages/eslint-config/src/config/javascript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ export function javascript() {
{ disallowTemplateShorthand: true, allow: ["!!"] },
], // forbid code like `const num = +str`;
"no-invalid-this": "error",
"no-lonely-if": "error",
"no-multi-assign": "error",
"no-object-constructor": "error",
"no-param-reassign": "error",
Expand Down Expand Up @@ -432,21 +433,43 @@ export function javascript() {
"unicorn/no-abusive-eslint-disable": "error",
"unicorn/no-array-callback-reference": "error",
"unicorn/no-array-method-this-argument": "error",
"unicorn/no-await-in-promise-methods": "error",
"unicorn/no-for-loop": "error",
"unicorn/no-instanceof-array": "error",
"unicorn/no-lonely-if": "error",
"unicorn/no-negation-in-equality-check": "error",
"unicorn/no-new-array": "error",
"unicorn/no-new-buffer": "error",
"unicorn/no-process-exit": "error",
"unicorn/no-single-promise-in-promise-methods": "error",
"unicorn/no-static-only-class": "error",
"unicorn/no-thenable": "error",
"unicorn/no-this-assignment": "error",
"unicorn/no-typeof-undefined": "error",
"unicorn/no-unreadable-array-destructuring": "error",
"unicorn/no-unreadable-iife": "error",
"unicorn/no-useless-fallback-in-spread": "error",
"unicorn/no-useless-spread": "error",
"unicorn/no-useless-switch-case": "error",
"unicorn/no-zero-fractions": "error",
"unicorn/prefer-array-flat-map": "error",
"unicorn/prefer-date-now": "error",
"unicorn/prefer-export-from": "error",
"unicorn/prefer-global-this": "error",
"unicorn/prefer-includes": "error",
"unicorn/prefer-logical-operator-over-ternary": "error",
"unicorn/prefer-math-min-max": "error",
"unicorn/prefer-module": "error",
"unicorn/prefer-negative-index": "error",
"unicorn/prefer-number-properties": "error",
"unicorn/prefer-optional-catch-binding": "error",
"unicorn/prefer-regexp-test": "error",
"unicorn/prefer-string-replace-all": "error",
"unicorn/prefer-string-slice": "error",
"unicorn/prefer-ternary": "error",
"unicorn/require-array-join-separator": "error",
"unicorn/require-number-to-fixed-digits-argument": "error",
"unicorn/text-encoding-identifier-case": "error",
"unicorn/throw-new-error": "error",

"@fenge/call-arguments-length": "error",
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-config/test/no-duplicated.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function count(content: string, substring: string) {
await describe("no duplicated", async () => {
await it("no duplicated js rules is defined", async () => {
const configContent = await prettier.format(
(await fs.readFile("./src/config/javascript.ts", "utf-8")).replace(
(await fs.readFile("./src/config/javascript.ts", "utf8")).replace(
"// prettier-ignore",
"",
),
Expand All @@ -33,7 +33,7 @@ await describe("no duplicated", async () => {

await it("no duplicated ts rules is defined", async () => {
const configContent = await prettier.format(
(await fs.readFile("./src/config/typescript.ts", "utf-8")).replace(
(await fs.readFile("./src/config/typescript.ts", "utf8")).replace(
"// prettier-ignore",
"",
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function check(filename: string, source: string) {
const isDir = memoize((filePath: string) => {
try {
return fs.statSync(filePath).isDirectory();
} catch (e) {
} catch {
return false;
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function isObject(value: unknown) {
function isFile(filePath: string) {
try {
return fs.statSync(filePath).isFile();
} catch (e) {
} catch {
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function isValidBinPath(filename, binPath) {
const filePath = path.resolve(path.dirname(filename), binPath);
try {
return fs.readFileSync(filePath, "utf8").trimStart().startsWith("#!");
} catch (e) {
} catch {
return false;
}
}
2 changes: 1 addition & 1 deletion packages/fenge/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export async function resolveConfig(module, loadPath) {
*/
export async function importJson(importMetaUrl, jsonPath) {
return JSON.parse(
await fs.readFile(path.resolve(dir(importMetaUrl), jsonPath), "utf-8"),
await fs.readFile(path.resolve(dir(importMetaUrl), jsonPath), "utf8"),
);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/smells/src/analyze.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function isJs(file) {
* @param {string} filepath ts or js file absolute path
*/
async function getAnalysis(filepath) {
const code = await fs.readFile(filepath, "utf-8");
const code = await fs.readFile(filepath, "utf8");
const result = {
/** @type {{start:{line:number,column:number}}[]} */
anyTypes: [],
Expand Down

0 comments on commit 3f4e737

Please sign in to comment.