Skip to content

Commit

Permalink
Switch to eslint-plugin-n (#614)
Browse files Browse the repository at this point in the history
  • Loading branch information
timostamm authored Nov 16, 2023
1 parent c831309 commit f7375ad
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 128 deletions.
117 changes: 57 additions & 60 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

const {readdirSync, existsSync} = require("fs");
const {join} = require("path");
const { readdirSync, existsSync } = require("fs");
const { join } = require("path");

module.exports = {
env: {
Expand All @@ -27,79 +27,76 @@ module.exports = {
"packages/*/.tmp/**",
"node_modules/**",
],
plugins: ["@typescript-eslint", "node", "import"],
plugins: ["@typescript-eslint", "n", "import"],
// Rules and settings that do not require a non-default parser
extends: [
"eslint:recommended",
],
extends: ["eslint:recommended"],
rules: {
"no-console": "error",
"import/no-duplicates": "off",
},
settings: {},
overrides: [
...readdirSync("packages", {withFileTypes: true})
.filter(entry => entry.isDirectory())
.map(entry => join("packages", entry.name))
.filter(dir => existsSync(join(dir, "tsconfig.json")))
.map(dir => {
return {
files: [join(dir, "src/**/*.ts")],
parser: "@typescript-eslint/parser",
parserOptions: {
project: "./tsconfig.json",
tsconfigRootDir: dir,
},
settings: {
"import/resolver": {
"typescript": {
"project": "packages/*/tsconfig.json",
}
}
},
extends: [
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"plugin:import/recommended",
"plugin:import/typescript",
],
rules: {
"@typescript-eslint/strict-boolean-expressions": "error",
"@typescript-eslint/no-unnecessary-condition": "error",
"@typescript-eslint/array-type": "off", // we use complex typings, where Array is actually more readable than T[]
"@typescript-eslint/switch-exhaustiveness-check": "error",
"@typescript-eslint/prefer-nullish-coalescing": "error",
"@typescript-eslint/no-unnecessary-boolean-literal-compare": "error",
"@typescript-eslint/no-invalid-void-type": "error",
"@typescript-eslint/no-base-to-string": "error",
"import/no-cycle": "error",
"import/no-duplicates": "off",
...readdirSync("packages", { withFileTypes: true })
.filter((entry) => entry.isDirectory())
.map((entry) => join("packages", entry.name))
.filter((dir) => existsSync(join(dir, "tsconfig.json")))
.map((dir) => {
return {
files: [join(dir, "src/**/*.ts")],
parser: "@typescript-eslint/parser",
parserOptions: {
project: "./tsconfig.json",
tsconfigRootDir: dir,
},
settings: {
"import/resolver": {
typescript: {
project: "packages/*/tsconfig.json",
},
},
};
}),
},
extends: [
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"plugin:import/recommended",
"plugin:import/typescript",
],
rules: {
"@typescript-eslint/strict-boolean-expressions": "error",
"@typescript-eslint/no-unnecessary-condition": "error",
"@typescript-eslint/array-type": "off", // we use complex typings, where Array is actually more readable than T[]
"@typescript-eslint/switch-exhaustiveness-check": "error",
"@typescript-eslint/prefer-nullish-coalescing": "error",
"@typescript-eslint/no-unnecessary-boolean-literal-compare":
"error",
"@typescript-eslint/no-invalid-void-type": "error",
"@typescript-eslint/no-base-to-string": "error",
"import/no-cycle": "error",
"import/no-duplicates": "off",
},
};
}),
// For scripts and configurations, use Node.js rules
{
files: ["**/*.{js,mjs,cjs}"],
parserOptions: {
ecmaVersion: 13, // ES2022 - https://eslint.org/docs/latest/use/configure/language-options#specifying-environments
},
extends: ["eslint:recommended", "plugin:node/recommended"],
extends: ["eslint:recommended", "plugin:n/recommended"],
rules: {
"node/shebang": "off", // this plugin only determines shebang necessary for files that are in a package.json "bin" field
"node/exports-style": ["error", "module.exports"],
"node/file-extension-in-import": ["error", "always"],
"node/prefer-global/buffer": ["error", "always"],
"node/prefer-global/console": ["error", "always"],
"node/prefer-global/process": ["error", "always"],
"node/prefer-global/url-search-params": ["error", "always"],
"node/prefer-global/url": ["error", "always"],
"node/prefer-promises/dns": "error",
"node/prefer-promises/fs": "error",
"no-process-exit": "off",
"node/no-unsupported-features/node-builtins": ["error", {
"version": ">=16.0.0",
"ignores": []
}]
"n/shebang": "off", // this rule reports _any_ shebang outside of an npm binary as an error
"n/prefer-global/process": "off",
"n/no-process-exit": "off",
"n/exports-style": ["error", "module.exports"],
"n/file-extension-in-import": ["error", "always"],
"n/prefer-global/buffer": ["error", "always"],
"n/prefer-global/console": ["error", "always"],
"n/prefer-global/url-search-params": ["error", "always"],
"n/prefer-global/url": ["error", "always"],
"n/prefer-promises/dns": "error",
"n/prefer-promises/fs": "error",
"n/no-unsupported-features/node-builtins": "error",
"n/no-unsupported-features/es-syntax": "error",
},
},
],
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ lint: node_modules $(BUILD)/protobuf $(BUILD)/protobuf-test $(BUILD)/protobuf-co

.PHONY: format
format: node_modules ## Format all files, adding license headers
npx prettier --write '**/*.{json,js,jsx,ts,tsx,css,mjs}' --log-level error
npx prettier --write '**/*.{json,js,jsx,ts,tsx,css,mjs,cjs}' --log-level error
npx license-header --ignore packages/protobuf/src/google/varint.ts

.PHONY: bench
Expand Down
119 changes: 57 additions & 62 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@
},
"devDependencies": {
"@arethetypeswrong/cli": "^0.13.0",
"@bufbuild/license-header": "^0.0.4",
"@types/node": "^20.8.8",
"@typescript-eslint/eslint-plugin": "^6.9.1",
"@typescript-eslint/parser": "^6.9.1",
"eslint": "^8.50.0",
"eslint-import-resolver-typescript": "^3.6.0",
"eslint-plugin-import": "^2.28.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-n": "^16.3.1",
"jest": "^29.7.0",
"prettier": "^3.0.0",
"typescript": "^5.2.2",
"@types/node": "^20.8.8",
"@bufbuild/license-header": "^0.0.4",
"jest": "^29.7.0"
"typescript": "^5.2.2"
},
"//": "avoid hoisting, see packages/protoplugin/src/ecmascript/transpile.ts",
"dependencies": {
Expand Down

0 comments on commit f7375ad

Please sign in to comment.