Skip to content

Commit

Permalink
chore: add prettier & lint-staged (eslint-community#7)
Browse files Browse the repository at this point in the history
* chore: add prettier & lint-staged

the package was using eslint to enforce a code style(@mysticatea/eslint-config)
while it's no longer maintained. It just added a prettier config to be close to
the eslint config

* fix: ignore .eslintcache

* chore: do not run prettier on md files for less changes

* chore: fix linting errors

refs: prettier/prettier#12137

* chore: prettier lib/* tests/lib/*

* chore: add eol
  • Loading branch information
aladdin-add authored Jan 27, 2022
1 parent df759eb commit 4deaca7
Show file tree
Hide file tree
Showing 74 changed files with 356 additions and 511 deletions.
11 changes: 8 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@
// to make the ci passing.
module.exports = {
reportUnusedDisableDirectives: true,
extends: ["eslint:recommended", "plugin:n/recommended", "plugin:eslint-plugin/recommended"],
extends: [
"eslint:recommended",
"plugin:n/recommended",
"plugin:eslint-plugin/recommended",
"prettier",
],
env: {
mocha: true,
}
};
},
}

// const version = require("./package.json").version

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/npm-debug.log
/node_modules
/test.js
.eslintcache
1 change: 1 addition & 0 deletions .husky/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx lint-staged
16 changes: 16 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"useTabs": false,
"semi": false,
"tabWidth": 4,
"arrowParens": "avoid",
"overrides": [
{
"files": "*.md",
"options": {
"printWidth": 70,
"trailingComma": "none",
"proseWrap": "never"
}
}
]
}
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ module.exports = {
"prefer-promises/dns": require("./rules/prefer-promises/dns"),
"prefer-promises/fs": require("./rules/prefer-promises/fs"),
"process-exit-as-throw": require("./rules/process-exit-as-throw"),
"shebang": require("./rules/shebang"),
shebang: require("./rules/shebang"),

// Deprecated rules.
"no-hide-core-modules": require("./rules/no-hide-core-modules"),
Expand Down
3 changes: 1 addition & 2 deletions lib/rules/callback-return.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ module.exports = {
description: "require `return` statements after callbacks",
category: "Stylistic Issues",
recommended: false,
url:
"https://github.com/weiran-zsd/eslint-plugin-node/blob/HEAD/docs/rules/callback-return.md",
url: "https://github.com/weiran-zsd/eslint-plugin-node/blob/HEAD/docs/rules/callback-return.md",
},
schema: [
{
Expand Down
3 changes: 1 addition & 2 deletions lib/rules/exports-style.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,7 @@ module.exports = {
description: "enforce either `module.exports` or `exports`",
category: "Stylistic Issues",
recommended: false,
url:
"https://github.com/weiran-zsd/eslint-plugin-node/blob/HEAD/docs/rules/exports-style.md",
url: "https://github.com/weiran-zsd/eslint-plugin-node/blob/HEAD/docs/rules/exports-style.md",
},
type: "suggestion",
fixable: null,
Expand Down
6 changes: 3 additions & 3 deletions lib/rules/file-extension-in-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ const fs = require("fs")
const getTryExtensions = require("../util/get-try-extensions")
const visitImport = require("../util/visit-import")
const packageNamePattern = /^(?:@[^/\\]+[/\\])?[^/\\]+$/u
const corePackageOverridePattern = /^(?:assert|async_hooks|buffer|child_process|cluster|console|constants|crypto|dgram|dns|domain|events|fs|http|http2|https|inspector|module|net|os|path|perf_hooks|process|punycode|querystring|readline|repl|stream|string_decoder|sys|timers|tls|trace_events|tty|url|util|v8|vm|worker_threads|zlib)[/\\]$/u
const corePackageOverridePattern =
/^(?:assert|async_hooks|buffer|child_process|cluster|console|constants|crypto|dgram|dns|domain|events|fs|http|http2|https|inspector|module|net|os|path|perf_hooks|process|punycode|querystring|readline|repl|stream|string_decoder|sys|timers|tls|trace_events|tty|url|util|v8|vm|worker_threads|zlib)[/\\]$/u

/**
* Get all file extensions of the files which have the same basename.
Expand Down Expand Up @@ -38,8 +39,7 @@ module.exports = {
"enforce the style of file extensions in `import` declarations",
category: "Stylistic Issues",
recommended: false,
url:
"https://github.com/weiran-zsd/eslint-plugin-node/blob/HEAD/docs/rules/file-extension-in-import.md",
url: "https://github.com/weiran-zsd/eslint-plugin-node/blob/HEAD/docs/rules/file-extension-in-import.md",
},
fixable: "code",
messages: {
Expand Down
3 changes: 1 addition & 2 deletions lib/rules/global-require.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ module.exports = {
"require `require()` calls to be placed at top-level module scope",
category: "Stylistic Issues",
recommended: false,
url:
"https://github.com/weiran-zsd/eslint-plugin-node/blob/HEAD/docs/rules/global-require.md",
url: "https://github.com/weiran-zsd/eslint-plugin-node/blob/HEAD/docs/rules/global-require.md",
},
fixable: null,
schema: [],
Expand Down
3 changes: 1 addition & 2 deletions lib/rules/handle-callback-err.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ module.exports = {
description: "require error handling in callbacks",
category: "Possible Errors",
recommended: false,
url:
"https://github.com/weiran-zsd/eslint-plugin-node/blob/HEAD/docs/rules/handle-callback-err.md",
url: "https://github.com/weiran-zsd/eslint-plugin-node/blob/HEAD/docs/rules/handle-callback-err.md",
},
fixable: null,
schema: [
Expand Down
3 changes: 1 addition & 2 deletions lib/rules/no-callback-literal.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ module.exports = {
"ensure Node.js-style error-first callback pattern is followed",
category: "Possible Errors",
recommended: false,
url:
"https://github.com/weiran-zsd/eslint-plugin-node/blob/HEAD/docs/rules/no-callback-literal.md",
url: "https://github.com/weiran-zsd/eslint-plugin-node/blob/HEAD/docs/rules/no-callback-literal.md",
},
type: "problem",
fixable: null,
Expand Down
18 changes: 7 additions & 11 deletions lib/rules/no-deprecated-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ const modules = {
_linklist: {
[READ]: { since: "5.0.0", replacedBy: null },
},

_stream_wrap: {
[READ]: { since: "12.0.0", replacedBy: null },
},

async_hooks: {
currentId: {
[READ]: {
Expand Down Expand Up @@ -659,8 +659,8 @@ function toName(type, path) {
return type === ReferenceTracker.CALL
? `${baseName}()`
: type === ReferenceTracker.CONSTRUCT
? `new ${baseName}()`
: baseName
? `new ${baseName}()`
: baseName
}

/**
Expand All @@ -685,8 +685,7 @@ module.exports = {
description: "disallow deprecated APIs",
category: "Best Practices",
recommended: true,
url:
"https://github.com/weiran-zsd/eslint-plugin-node/blob/HEAD/docs/rules/no-deprecated-api.md",
url: "https://github.com/weiran-zsd/eslint-plugin-node/blob/HEAD/docs/rules/no-deprecated-api.md",
},
type: "problem",
fixable: null,
Expand Down Expand Up @@ -722,11 +721,8 @@ module.exports = {
],
},
create(context) {
const {
ignoredModuleItems,
ignoredGlobalItems,
version,
} = parseOptions(context)
const { ignoredModuleItems, ignoredGlobalItems, version } =
parseOptions(context)

/**
* Reports a use of a deprecated API.
Expand Down
3 changes: 1 addition & 2 deletions lib/rules/no-exports-assign.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ module.exports = {
description: "disallow the assignment to `exports`",
category: "Possible Errors",
recommended: true,
url:
"https://github.com/weiran-zsd/eslint-plugin-node/blob/HEAD/docs/rules/no-exports-assign.md",
url: "https://github.com/weiran-zsd/eslint-plugin-node/blob/HEAD/docs/rules/no-exports-assign.md",
},
fixable: null,
messages: {
Expand Down
3 changes: 1 addition & 2 deletions lib/rules/no-extraneous-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ module.exports = {
"disallow `import` declarations which import extraneous modules",
category: "Possible Errors",
recommended: true,
url:
"https://github.com/weiran-zsd/eslint-plugin-node/blob/HEAD/docs/rules/no-extraneous-import.md",
url: "https://github.com/weiran-zsd/eslint-plugin-node/blob/HEAD/docs/rules/no-extraneous-import.md",
},
type: "problem",
fixable: null,
Expand Down
3 changes: 1 addition & 2 deletions lib/rules/no-extraneous-require.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ module.exports = {
"disallow `require()` expressions which import extraneous modules",
category: "Possible Errors",
recommended: true,
url:
"https://github.com/weiran-zsd/eslint-plugin-node/blob/HEAD/docs/rules/no-extraneous-require.md",
url: "https://github.com/weiran-zsd/eslint-plugin-node/blob/HEAD/docs/rules/no-extraneous-require.md",
},
type: "problem",
fixable: null,
Expand Down
3 changes: 1 addition & 2 deletions lib/rules/no-hide-core-modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ module.exports = {
"disallow third-party modules which are hiding core modules",
category: "Possible Errors",
recommended: false,
url:
"https://github.com/weiran-zsd/eslint-plugin-node/blob/HEAD/docs/rules/no-hide-core-modules.md",
url: "https://github.com/weiran-zsd/eslint-plugin-node/blob/HEAD/docs/rules/no-hide-core-modules.md",
},
type: "problem",
deprecated: true,
Expand Down
3 changes: 1 addition & 2 deletions lib/rules/no-missing-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ module.exports = {
"disallow `import` declarations which import non-existence modules",
category: "Possible Errors",
recommended: true,
url:
"https://github.com/weiran-zsd/eslint-plugin-node/blob/HEAD/docs/rules/no-missing-import.md",
url: "https://github.com/weiran-zsd/eslint-plugin-node/blob/HEAD/docs/rules/no-missing-import.md",
},
type: "problem",
fixable: null,
Expand Down
3 changes: 1 addition & 2 deletions lib/rules/no-missing-require.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ module.exports = {
"disallow `require()` expressions which import non-existence modules",
category: "Possible Errors",
recommended: true,
url:
"https://github.com/weiran-zsd/eslint-plugin-node/blob/HEAD/docs/rules/no-missing-require.md",
url: "https://github.com/weiran-zsd/eslint-plugin-node/blob/HEAD/docs/rules/no-missing-require.md",
},
type: "problem",
fixable: null,
Expand Down
3 changes: 1 addition & 2 deletions lib/rules/no-mixed-requires.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ module.exports = {
"disallow `require` calls to be mixed with regular variable declarations",
category: "Stylistic Issues",
recommended: false,
url:
"https://github.com/weiran-zsd/eslint-plugin-node/blob/HEAD/docs/rules/no-mixed-requires.md",
url: "https://github.com/weiran-zsd/eslint-plugin-node/blob/HEAD/docs/rules/no-mixed-requires.md",
},
fixable: null,
schema: [
Expand Down
3 changes: 1 addition & 2 deletions lib/rules/no-new-require.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ module.exports = {
description: "disallow `new` operators with calls to `require`",
category: "Possible Errors",
recommended: false,
url:
"https://github.com/weiran-zsd/eslint-plugin-node/blob/HEAD/docs/rules/no-new-require.md",
url: "https://github.com/weiran-zsd/eslint-plugin-node/blob/HEAD/docs/rules/no-new-require.md",
},
fixable: null,
schema: [],
Expand Down
3 changes: 1 addition & 2 deletions lib/rules/no-path-concat.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,7 @@ module.exports = {
"disallow string concatenation with `__dirname` and `__filename`",
category: "Possible Errors",
recommended: false,
url:
"https://github.com/weiran-zsd/eslint-plugin-node/blob/HEAD/docs/rules/no-path-concat.md",
url: "https://github.com/weiran-zsd/eslint-plugin-node/blob/HEAD/docs/rules/no-path-concat.md",
},
fixable: null,
schema: [],
Expand Down
3 changes: 1 addition & 2 deletions lib/rules/no-process-env.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ module.exports = {
description: "disallow the use of `process.env`",
category: "Stylistic Issues",
recommended: false,
url:
"https://github.com/weiran-zsd/eslint-plugin-node/blob/HEAD/docs/rules/no-process-env.md",
url: "https://github.com/weiran-zsd/eslint-plugin-node/blob/HEAD/docs/rules/no-process-env.md",
},
fixable: null,
schema: [],
Expand Down
3 changes: 1 addition & 2 deletions lib/rules/no-process-exit.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ module.exports = {
description: "disallow the use of `process.exit()`",
category: "Possible Errors",
recommended: false,
url:
"https://github.com/weiran-zsd/eslint-plugin-node/blob/HEAD/docs/rules/no-process-exit.md",
url: "https://github.com/weiran-zsd/eslint-plugin-node/blob/HEAD/docs/rules/no-process-exit.md",
},
fixable: null,
schema: [],
Expand Down
3 changes: 1 addition & 2 deletions lib/rules/no-restricted-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ module.exports = {
"disallow specified modules when loaded by `import` declarations",
category: "Stylistic Issues",
recommended: false,
url:
"https://github.com/weiran-zsd/eslint-plugin-node/blob/HEAD/docs/rules/no-restricted-import.md",
url: "https://github.com/weiran-zsd/eslint-plugin-node/blob/HEAD/docs/rules/no-restricted-import.md",
},
fixable: null,
schema: [
Expand Down
3 changes: 1 addition & 2 deletions lib/rules/no-restricted-require.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ module.exports = {
description: "disallow specified modules when loaded by `require`",
category: "Stylistic Issues",
recommended: false,
url:
"https://github.com/weiran-zsd/eslint-plugin-node/blob/HEAD/docs/rules/no-restricted-require.md",
url: "https://github.com/weiran-zsd/eslint-plugin-node/blob/HEAD/docs/rules/no-restricted-require.md",
},
fixable: null,
schema: [
Expand Down
3 changes: 1 addition & 2 deletions lib/rules/no-sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ module.exports = {
description: "disallow synchronous methods",
category: "Stylistic Issues",
recommended: false,
url:
"https://github.com/weiran-zsd/eslint-plugin-node/blob/HEAD/docs/rules/no-sync.md",
url: "https://github.com/weiran-zsd/eslint-plugin-node/blob/HEAD/docs/rules/no-sync.md",
},
fixable: null,
schema: [
Expand Down
3 changes: 1 addition & 2 deletions lib/rules/no-unpublished-bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ module.exports = {
description: "disallow `bin` files that npm ignores",
category: "Possible Errors",
recommended: true,
url:
"https://github.com/weiran-zsd/eslint-plugin-node/blob/HEAD/docs/rules/no-unpublished-bin.md",
url: "https://github.com/weiran-zsd/eslint-plugin-node/blob/HEAD/docs/rules/no-unpublished-bin.md",
},
type: "problem",
fixable: null,
Expand Down
3 changes: 1 addition & 2 deletions lib/rules/no-unpublished-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ module.exports = {
"disallow `import` declarations which import private modules",
category: "Possible Errors",
recommended: true,
url:
"https://github.com/weiran-zsd/eslint-plugin-node/blob/HEAD/docs/rules/no-unpublished-import.md",
url: "https://github.com/weiran-zsd/eslint-plugin-node/blob/HEAD/docs/rules/no-unpublished-import.md",
},
type: "problem",
fixable: null,
Expand Down
3 changes: 1 addition & 2 deletions lib/rules/no-unpublished-require.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ module.exports = {
"disallow `require()` expressions which import private modules",
category: "Possible Errors",
recommended: true,
url:
"https://github.com/weiran-zsd/eslint-plugin-node/blob/HEAD/docs/rules/no-unpublished-require.md",
url: "https://github.com/weiran-zsd/eslint-plugin-node/blob/HEAD/docs/rules/no-unpublished-require.md",
},
type: "problem",
fixable: null,
Expand Down
6 changes: 3 additions & 3 deletions lib/rules/no-unsupported-features.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ const VERSION_SCHEMA = {
const DEFAULT_VERSION = "4.0.0"
const FUNC_TYPE = /^(?:Arrow)?Function(?:Declaration|Expression)$/u
const CLASS_TYPE = /^Class(?:Declaration|Expression)$/u
const DESTRUCTURING_PARENT_TYPE = /^(?:Function(?:Declaration|Expression)|ArrowFunctionExpression|AssignmentExpression|VariableDeclarator)$/u
const DESTRUCTURING_PARENT_TYPE =
/^(?:Function(?:Declaration|Expression)|ArrowFunctionExpression|AssignmentExpression|VariableDeclarator)$/u
const TOPLEVEL_SCOPE_TYPE = /^(?:global|function|module)$/u
const BINARY_NUMBER = /^0[bB]/u
const OCTAL_NUMBER = /^0[oO]/u
Expand Down Expand Up @@ -1050,8 +1051,7 @@ module.exports = {
"n/no-unsupported-features/es-syntax",
"n/no-unsupported-features/es-builtins",
],
url:
"https://github.com/weiran-zsd/eslint-plugin-node/blob/HEAD/docs/rules/no-unsupported-features.md",
url: "https://github.com/weiran-zsd/eslint-plugin-node/blob/HEAD/docs/rules/no-unsupported-features.md",
},
type: "problem",
deprecated: true,
Expand Down
3 changes: 1 addition & 2 deletions lib/rules/no-unsupported-features/es-builtins.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,7 @@ module.exports = {
"disallow unsupported ECMAScript built-ins on the specified version",
category: "Possible Errors",
recommended: true,
url:
"https://github.com/weiran-zsd/eslint-plugin-node/blob/HEAD/docs/rules/no-unsupported-features/es-builtins.md",
url: "https://github.com/weiran-zsd/eslint-plugin-node/blob/HEAD/docs/rules/no-unsupported-features/es-builtins.md",
},
type: "problem",
fixable: null,
Expand Down
3 changes: 1 addition & 2 deletions lib/rules/no-unsupported-features/es-syntax.js
Original file line number Diff line number Diff line change
Expand Up @@ -520,8 +520,7 @@ module.exports = {
"disallow unsupported ECMAScript syntax on the specified version",
category: "Possible Errors",
recommended: true,
url:
"https://github.com/weiran-zsd/eslint-plugin-node/blob/HEAD/docs/rules/no-unsupported-features/es-syntax.md",
url: "https://github.com/weiran-zsd/eslint-plugin-node/blob/HEAD/docs/rules/no-unsupported-features/es-syntax.md",
},
type: "problem",
fixable: null,
Expand Down
Loading

0 comments on commit 4deaca7

Please sign in to comment.