@u3u/eslint-config
Version:
My ESLint config
191 lines (184 loc) • 7.51 kB
JavaScript
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/ts-for-js.ts
var ts_for_js_exports = {};
__export(ts_for_js_exports, {
default: () => ts_for_js_default
});
module.exports = __toCommonJS(ts_for_js_exports);
// src/rules/newline-blocks.ts
var blockLike = ["block-like", "multiline-expression"];
var returnLike = ["return", "throw", "break", "continue", "debugger"];
var singlelineVars = ["singleline-const", "singleline-let", "singleline-var"];
var multilineVars = ["multiline-const", "multiline-let", "multiline-var"];
var newlineBlocks = [
// newline-before-blocks
{ blankLine: "always", next: [...blockLike, ...returnLike], prev: "*" },
// newline-after-blocks
{ blankLine: "always", next: "*", prev: [...blockLike, ...multilineVars] },
// newline-after-directive
{ blankLine: "always", next: "*", prev: "directive" },
{ blankLine: "any", next: "directive", prev: "directive" },
// newline-after-import
{ blankLine: "always", next: "*", prev: "import" },
{ blankLine: "any", next: "import", prev: "import" },
// newline-after-var
{ blankLine: "always", next: "*", prev: singlelineVars },
{ blankLine: "any", next: singlelineVars, prev: singlelineVars }
];
// src/utils/define-config.ts
var defineConfig = (config) => {
return config;
};
// src/utils/env.ts
var import_node_fs = __toESM(require("fs"));
var import_node_path = __toESM(require("path"));
var import_local_pkg = require("local-pkg");
var env = {
get hasTsconfig() {
return import_node_fs.default.existsSync(env.tsconfigPath);
},
get isAstro() {
return (0, import_local_pkg.isPackageExists)("astro");
},
get isReact() {
return (0, import_local_pkg.isPackageExists)("react");
},
get isTs() {
return (0, import_local_pkg.isPackageExists)("typescript");
},
get isVue() {
return (0, import_local_pkg.isPackageExists)("vue");
},
get tsconfig() {
return process.env.ESLINT_TSCONFIG || "tsconfig.json";
},
get tsconfigPath() {
return import_node_path.default.resolve(process.cwd(), env.tsconfig);
},
get useTsForJs() {
return process.env.USE_TS_FOR_JS === "true";
}
};
// src/ts-for-js.ts
var { tsconfig } = env;
var ts_for_js_default = defineConfig({
extends: ["plugin:typescript-sort-keys/recommended"],
parser: "@typescript-eslint/parser",
parserOptions: {
project: tsconfig,
tsconfigRootDir: process.cwd()
},
plugins: ["@typescript-eslint"],
rules: {
"@typescript-eslint/array-type": "warn",
"@typescript-eslint/ban-tslint-comment": "warn",
"@typescript-eslint/ban-types": "warn",
"@typescript-eslint/consistent-generic-constructors": "warn",
"@typescript-eslint/consistent-indexed-object-style": "warn",
"@typescript-eslint/consistent-type-assertions": "warn",
"@typescript-eslint/consistent-type-definitions": "warn",
"@typescript-eslint/consistent-type-exports": "warn",
"@typescript-eslint/consistent-type-imports": [
"warn",
{
disallowTypeAnnotations: false,
fixStyle: "inline-type-imports"
}
],
"@typescript-eslint/dot-notation": ["warn", { allowIndexSignaturePropertyAccess: true, allowKeywords: false }],
"@typescript-eslint/explicit-member-accessibility": ["warn", { accessibility: "no-public" }],
// '@typescript-eslint/lines-around-comment': [
// 'warn',
// {
// ...linesAroundComment,
// allowEnumEnd: true,
// allowEnumStart: true,
// allowInterfaceEnd: true,
// allowInterfaceStart: true,
// allowModuleEnd: true,
// allowModuleStart: true,
// allowTypeEnd: true,
// allowTypeStart: true,
// },
// ],
"@typescript-eslint/lines-between-class-members": "warn",
"@typescript-eslint/method-signature-style": ["warn", "method"],
"@typescript-eslint/no-array-constructor": "warn",
"@typescript-eslint/no-confusing-non-null-assertion": "warn",
"@typescript-eslint/no-duplicate-type-constituents": "warn",
"@typescript-eslint/no-extra-non-null-assertion": "warn",
"@typescript-eslint/no-import-type-side-effects": "warn",
"@typescript-eslint/no-inferrable-types": "warn",
"@typescript-eslint/no-meaningless-void-operator": "warn",
"@typescript-eslint/no-unnecessary-boolean-literal-compare": "warn",
// '@typescript-eslint/no-unnecessary-condition': ['warn', { allowConstantLoopConditions: true }],
"@typescript-eslint/no-unnecessary-qualifier": "warn",
"@typescript-eslint/no-unnecessary-type-arguments": "warn",
"@typescript-eslint/no-unnecessary-type-assertion": "warn",
"@typescript-eslint/no-useless-empty-export": "warn",
"@typescript-eslint/non-nullable-type-assertion-style": "warn",
"@typescript-eslint/padding-line-between-statements": [
"warn",
...newlineBlocks,
{
blankLine: "always",
next: ["interface", "type", "export"],
prev: "*"
}
],
"@typescript-eslint/prefer-as-const": "warn",
"@typescript-eslint/prefer-for-of": "warn",
"@typescript-eslint/prefer-function-type": "warn",
"@typescript-eslint/prefer-includes": "warn",
"@typescript-eslint/prefer-namespace-keyword": "warn",
// '@typescript-eslint/prefer-nullish-coalescing': 'warn',
"@typescript-eslint/prefer-optional-chain": "warn",
"@typescript-eslint/prefer-reduce-type-parameter": "warn",
"@typescript-eslint/prefer-regexp-exec": "warn",
"@typescript-eslint/prefer-string-starts-ends-with": "warn",
"@typescript-eslint/prefer-ts-expect-error": "warn",
// '@typescript-eslint/promise-function-async': 'warn',
"@typescript-eslint/return-await": "warn",
"@typescript-eslint/sort-type-constituents": "warn",
// Rules of Conflicts
"dot-notation": "off",
"lines-around-comment": "off",
"lines-between-class-members": "off",
"no-array-constructor": "off",
"no-return-await": "off",
"padding-line-between-statements": "off"
}
});
// fix-cjs-exports
if (module.exports.default) {
Object.assign(module.exports.default, module.exports);
module.exports = module.exports.default;
delete module.exports.default;
}
;