Skip to content

Commit

Permalink
chore: improve coding style
Browse files Browse the repository at this point in the history
  • Loading branch information
chihuo2104 committed Jul 3, 2022
1 parent 3104400 commit 638c4ea
Showing 27 changed files with 415 additions and 137 deletions.
3 changes: 0 additions & 3 deletions .eslintrc

This file was deleted.

286 changes: 286 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,286 @@
module.exports = {
env: {
es6: true,
browser: true,
node: true,
},
extends: [
"standard",
"plugin:import/recommended",
"plugin:eslint-comments/recommended",
"plugin:jsonc/recommended-with-jsonc",
"plugin:yml/standard",
"plugin:markdown/recommended",
],
ignorePatterns: [
"*.min.*",
"CHANGELOG.md",
"dist",
"LICENSE*",
"output",
"coverage",
"public",
"temp",
"packages-lock.json",
"pnpm-lock.yaml",
"yarn.lock",
"__snapshots__",
"!.github",
"!.vitepress",
"!.vscode",
],
plugins: [
"html",
"unicorn",
],
settings: {
"import/resolver": {
node: { extensions: [".js", ".mjs", ".ts", ".d.ts"] },
},
},
overrides: [
{
files: ["*.json", "*.json5"],
parser: "jsonc-eslint-parser",
rules: {
"quotes": ["warn", "double"],
"quote-props": ["warn", "consistent-as-needed"],
"comma-dangle": ["warn", "always"],
},
},
{
files: ["*.yaml", "*.yml"],
parser: "yaml-eslint-parser",
rules: {
"spaced-comment": "off",
},
},
{
files: ["package.json"],
parser: "jsonc-eslint-parser",
rules: {
"jsonc/sort-keys": [
"warn",
{
pathPattern: "^$",
order: [
"name",
"type",
"version",
"private",
"packageManager",
"description",
"keywords",
"license",
"author",
"repository",
"funding",
"main",
"module",
"types",
"unpkg",
"jsdelivr",
"exports",
"files",
"bin",
"sideEffects",
"scripts",
"peerDependencies",
"peerDependenciesMeta",
"dependencies",
"optionalDependencies",
"devDependencies",
"husky",
"lint-staged",
"eslintConfig",
],
},
{
pathPattern: "^(?:dev|peer|optional|bundled)?[Dd]ependencies$",
order: { type: "asc" },
},
],
},
},
{
files: ["*.js"],
rules: {
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/no-unused-vars": "off",
"no-unused-vars": "off",
"no-undef": "off",
},
},
{
files: ["scripts/**/*.*", "cli.*"],
rules: {
"no-console": "off",
},
},
{
files: ["*.test.ts", "*.test.js", "*.spec.ts", "*.spec.js"],
rules: {
"no-unused-expressions": "off",
},
},
{
// Code blocks in markdown file
files: ["**/*.md/*.*"],
rules: {
"@typescript-eslint/no-redeclare": "off",
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/no-var-requires": "off",
"import/no-unresolved": "off",
"no-alert": "off",
"no-console": "off",
"no-restricted-imports": "off",
"no-undef": "off",
"no-unused-expressions": "off",
"no-unused-vars": "off",
},
},
],
rules: {
// import
"import/order": "warn",
"import/first": "warn",
"import/no-mutable-exports": "warn",
"import/no-unresolved": "off",
"import/no-absolute-path": "off",

// Common
"semi": ["warn", "always"],
"curly": ["warn", "multi-or-nest", "consistent"],
"quotes": ["warn", "double"],
"quote-props": ["warn", "consistent-as-needed"],
"no-unused-vars": "warn",
"no-param-reassign": "off",
"array-bracket-spacing": ["warn", "never"],
"brace-style": ["warn", "1tbs", { allowSingleLine: true }],
"block-spacing": ["warn", "always"],
"camelcase": "off",
"comma-spacing": ["warn", { before: false, after: true }],
"comma-style": ["warn", "last"],
"comma-dangle": ["warn", "always-multiline"],
"no-constant-condition": "warn",
"no-debugger": "warn",
"no-console": ["warn", { allow: ["error", "warn"] }],
"no-cond-assign": ["warn", "always"],
"func-call-spacing": ["off", "never"],
"key-spacing": ["warn", { beforeColon: false, afterColon: true }],
"indent": ["warn", 2, { SwitchCase: 1, VariableDeclarator: 1, outerIIFEBody: 1 }],
"no-restricted-syntax": [
"warn",
"DebuggerStatement",
"LabeledStatement",
"WithStatement",
],
"object-curly-spacing": ["warn", "always"],
"no-return-await": "off",

// es6
"no-var": "warn",
"prefer-const": [
"warn",
{
destructuring: "any",
ignoreReadBeforeAssign: true,
},
],
"prefer-arrow-callback": [
"warn",
{
allowNamedFunctions: false,
allowUnboundThis: true,
},
],
"object-shorthand": [
"warn",
"always",
{
ignoreConstructors: false,
avoidQuotes: true,
},
],
"prefer-rest-params": "warn",
"prefer-spread": "warn",
// "prefer-template": "warn",
"template-curly-spacing": "warn",
"arrow-parens": ["warn", "as-needed", { requireForBlockBody: true }],
"generator-star-spacing": "off",
"spaced-comment": ["warn", "always", {
line: {
markers: ["/"],
exceptions: ["/", "#"],
},
block: {
markers: ["!"],
exceptions: ["*"],
balanced: true,
},
}],

// best-practice
"array-callback-return": "warn",
"block-scoped-var": "warn",
"consistent-return": "off",
"complexity": ["off", 11],
"eqeqeq": ["warn", "smart"],
"no-case-declarations": "warn",
"no-multi-spaces": "warn",
"no-multi-str": "warn",
"no-with": "warn",
"no-useless-escape": "off",
"vars-on-top": "warn",
"require-await": "off",
"no-return-assign": "off",
"operator-linebreak": ["warn", "before"],

// unicorns
// Pass error message when throwing errors
"unicorn/error-message": "warn",
// Uppercase regex escapes
"unicorn/escape-case": "warn",
// Array.isArray instead of instanceof
"unicorn/no-array-instanceof": "warn",
// Prevent deprecated `new Buffer()`
"unicorn/no-new-buffer": "warn",
// Keep regex literals safe!
"unicorn/no-unsafe-regex": "off",
// Lowercase number formatting for octal, hex, binary (0x1'error' instead of 0X1'error')
"unicorn/number-literal-case": "warn",
// ** instead of Math.pow()
"unicorn/prefer-exponentiation-operator": "warn",
// includes over indexOf when checking for existence
"unicorn/prefer-includes": "warn",
// String methods startsWith/endsWith instead of more complicated stuff
"unicorn/prefer-starts-ends-with": "warn",
// textContent instead of innerText
"unicorn/prefer-text-content": "warn",
// Enforce throwing type error when throwing error while checking typeof
"unicorn/prefer-type-error": "warn",
// Use new when throwing error
"unicorn/throw-new-error": "warn",

"no-use-before-define": ["warn", { functions: false, classes: false, variables: true }],
"eslint-comments/disable-enable-pair": "off",
"import/no-named-as-default-member": "off",
"n/no-callback-literal": "off",

"sort-imports": [
"warn",
{
ignoreCase: false,
ignoreDeclarationSort: true,
ignoreMemberSort: false,
memberSyntaxSortOrder: ["none", "all", "multiple", "single"],
allowSeparatedGroups: false,
},
],

// yml
"yml/quotes": ["warn", { prefer: "double", avoidEscape: false }],
"yml/no-empty-document": "off",
},
};
3 changes: 2 additions & 1 deletion App/LangData.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { readFileSync } = require("fs");
const path = require("path");

module.exports = JSON.parse(readFileSync(`${__dirname}/lang.json`, "utf8"));
module.exports = JSON.parse(readFileSync(path.join(__dirname, "/lang.json"), "utf8"));
2 changes: 1 addition & 1 deletion App/add_a_article.js
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ module.exports = function () {
const tempString = randomString(12);

if (existsSync(`${rootDir}/data/articles/${tempString}.md`)) {

;
} else {
const dateobject = new Date();
const datenow = dateobject.toLocaleDateString();
2 changes: 1 addition & 1 deletion App/add_a_page.js
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ module.exports = function () {
const tempString = randomString(12);

if (existsSync(`${rootDir}/data/pages/${tempString}.md`)) {

;
} else {
blog["页面列表"].unshift({
"页面标题": "",
4 changes: 2 additions & 2 deletions App/check_migrate.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const fs = require("fs");
const { constants } = require("fs");
// const fs = require("fs");
// const { constants } = require("fs");
const dialog = require("@electron/remote").dialog;
const currentProgramVersion = require("./currentProgramVersion.js");

6 changes: 3 additions & 3 deletions App/check_update.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const path = require("path");
const app = require("@electron/remote").app;
// const path = require("path");
// const app = require("@electron/remote").app;
const os = require("os");
const currentProgramVersion = require("./currentProgramVersion.js").toString();
const download_update = require("./download_update.js");
const os = require("os");

progress_modal = new bootstrap.Modal(document.getElementById("update-progress-dialog"), {
backdrop: "static",
3 changes: 2 additions & 1 deletion App/currentProgramVersion.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { readFileSync } = require("fs");
const path = require("path");

const currentProgramVersion = JSON.parse(readFileSync(`${__dirname}/App.json`), "utf8").currentProgramVersion;
const currentProgramVersion = JSON.parse(readFileSync(path.join(__dirname, "/App.json"), "utf8")).currentProgramVersion;

module.exports = currentProgramVersion;
4 changes: 2 additions & 2 deletions App/delete_article.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const dialog = require("@electron/remote").dialog;
const { rmSync } = require("fs");
const dialog = require("@electron/remote").dialog;

module.exports = function (i) {
const submitDialog = dialog.showMessageBoxSync({
@@ -30,6 +30,6 @@ module.exports = function (i) {

window.location.reload();
} else {

;
}
};
4 changes: 2 additions & 2 deletions App/delete_page.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const dialog = require("@electron/remote").dialog;
const { rmSync } = require("fs");
const dialog = require("@electron/remote").dialog;

module.exports = function (i) {
const submitDialog = dialog.showMessageBoxSync({
@@ -29,6 +29,6 @@ module.exports = function (i) {

window.location.reload();
} else {

;
}
};
6 changes: 3 additions & 3 deletions App/download_update.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const fs = require("fs");
const path = require("path");
const request = require("request");
const dialog = require("@electron/remote").dialog;
// const dialog = require("@electron/remote").dialog;
const win = require("@electron/remote").getCurrentWindow();
const path = require("path");
const app = require("@electron/remote").app;
const os = require("os");
// const os = require("os");
const { shell } = require("electron");

module.exports = function () {
Loading

0 comments on commit 638c4ea

Please sign in to comment.