Skip to content

Commit

Permalink
adjust rules (#241)
Browse files Browse the repository at this point in the history
Signed-off-by: Kangrui Johann Ye <[email protected]>
  • Loading branch information
strawberry-choco authored Oct 11, 2024
1 parent b9956fc commit db5b3ef
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 29 deletions.
2 changes: 2 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ export default tseslint.config(
'packages/eslint-plugin-typescript/src/configs/recommended-typescript/rules/format.ts',
'packages/eslint-plugin-typescript/src/configs/recommended-typescript/rules/import.ts',
'packages/eslint-plugin-typescript/src/configs/recommended-typescript/rules/rxjs.ts',
'packages/eslint-plugin-typescript/src/rules/package/*',
'packages/eslint-plugin-typescript/src/rules/ts-config/*',
'packages/eslint-plugin-typescript/src/rules/typescript/*.spec.ts',
'scripts/*',
'.eslintrc.format.js',
'eslint.config.mjs',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cloudflight/eslint-plugin",
"version": "1.0.0-rc3",
"version": "1.0.0-rc4",
"private": true,
"volta": {
"node": "20.12.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin-angular/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cloudflight/eslint-plugin-angular",
"version": "1.0.0-rc3",
"version": "1.0.0-rc4",
"description": "Cloudflight eslint-plugin & eslint-config for angular",
"volta": {
"extends": "../../package.json"
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin-node/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cloudflight/eslint-plugin-node",
"version": "1.0.0-rc3",
"version": "1.0.0-rc4",
"description": "Cloudflight eslint-plugin & eslint-config for node",
"volta": {
"extends": "../../package.json"
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin-node/src/configs/security.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function warningEntryToError(value: TSESLint.Linter.RuleEntry): TSESLint.Linter.
const level = Array.isArray(value) ? value[0] : value;
const updatedLevel = warningLevelToError(level);

return Array.isArray(value) ? [updatedLevel, value.slice(1)] : updatedLevel;
return Array.isArray(value) ? [updatedLevel, ...value.slice(1)] : updatedLevel;
}

function warningLevelToError(level: TSESLint.Linter.RuleLevel): TSESLint.Linter.RuleLevel {
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin-react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cloudflight/eslint-plugin-react",
"version": "1.0.0-rc3",
"version": "1.0.0-rc4",
"description": "Cloudflight eslint-plugin & eslint-config for React",
"volta": {
"extends": "../../package.json"
Expand Down
6 changes: 1 addition & 5 deletions packages/eslint-plugin-typescript/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cloudflight/eslint-plugin-typescript",
"version": "1.0.0-rc3",
"version": "1.0.0-rc4",
"description": "Cloudflight eslint-plugin & eslint-config for typescript",
"volta": {
"extends": "../../package.json"
Expand Down Expand Up @@ -30,10 +30,6 @@
"@eslint/js": "^9.11.1",
"@typescript-eslint/eslint-plugin": "^8.8.0",
"@typescript-eslint/parser": "^8.8.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-json-es": "^1.6.0",
"eslint-plugin-rxjs": "^5.0.3",
"eslint-plugin-simple-import-sort": "^12.1.0",
"typescript-eslint": "^8.8.0"
},
"peerDependencies": {
Expand Down
1 change: 1 addition & 0 deletions packages/eslint-plugin-typescript/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const cloudflightTypescriptConfig = tseslint.config(
extends: [
pluginJs.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
...tseslint.configs.strictTypeChecked,
],
rules: {
...eslintRules,
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin-vue/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cloudflight/eslint-plugin-vue",
"version": "1.0.0-rc3",
"version": "1.0.0-rc4",
"description": "Cloudflight eslint-plugin & eslint-config for vue",
"volta": {
"extends": "../../package.json"
Expand Down
41 changes: 39 additions & 2 deletions packages/eslint-plugin-vue/src/configs/vue.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
import {TSESLint} from '@typescript-eslint/utils';
// @ts-expect-error .d.ts file for eslint-plugin-vue has been implemented but not released yet
// if the following line fails to build after updating the version, simply remove this comment
import pluginVue from 'eslint-plugin-vue';

const htmlIndent = 4;
// .d.ts file for eslint-plugin-vue has been implemented but not released yet, if the
// following line fails to build after updating the version, simply remove this comment
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/consistent-type-assertions
const recommendedConfigArray = pluginVue.configs['flat/recommended'] as TSESLint.FlatConfig.ConfigArray;
const recommendedRules = recommendedConfigArray
.reduce<Record<string, TSESLint.Linter.RuleEntry | undefined>>((acc, config) => ({...acc, ...config.rules}), {});
const updatedRules = Object.entries<TSESLint.Linter.RuleEntry | undefined>(recommendedRules)
.filter((entry): entry is [string, TSESLint.Linter.RuleEntry] => entry[1] != null)
.map(([key, value]) => [key, warningEntryToError(value)]);

export const vueRules: TSESLint.Linter.RulesRecord = {
// yes, we know this works correctly
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
...Object.fromEntries(updatedRules) as TSESLint.Linter.RulesRecord,
'vue/block-lang': [
'error',
{
Expand All @@ -24,7 +38,30 @@ export const vueRules: TSESLint.Linter.RulesRecord = {
},
],
'vue/html-button-has-type': 'error',
'vue/html-indent': ['error', htmlIndent],
'vue/no-ref-object-destructure': 'error',
'vue/no-undef-properties': 'error',
// disable stylistic rules
'vue/html-indent': 'off',
'vue/max-attributes-per-line': 'off',
'vue/html-self-closing': 'off',
'vue/singleline-html-element-content-newline': 'off',
'vue/multiline-html-element-content-newline': 'off',
'vue/html-closing-bracket-newline': 'off',
};

function warningEntryToError(value: TSESLint.Linter.RuleEntry): TSESLint.Linter.RuleEntry {
const level = Array.isArray(value) ? value[0] : value;
const updatedLevel = warningLevelToError(level);

return Array.isArray(value) ? [updatedLevel, ...value.slice(1)] : updatedLevel;
}

function warningLevelToError(level: TSESLint.Linter.RuleLevel): TSESLint.Linter.RuleLevel {
if (level === 'warn') {
return 'error';
} else if (level === 1) {
return 'error';
}

return level;
}
19 changes: 3 additions & 16 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -564,10 +564,6 @@ __metadata:
"@eslint/js": "npm:^9.11.1"
"@typescript-eslint/eslint-plugin": "npm:^8.8.0"
"@typescript-eslint/parser": "npm:^8.8.0"
eslint-plugin-import: "npm:^2.29.1"
eslint-plugin-json-es: "npm:^1.6.0"
eslint-plugin-rxjs: "npm:^5.0.3"
eslint-plugin-simple-import-sort: "npm:^12.1.0"
typescript: "npm:5.5.4"
typescript-eslint: "npm:^8.8.0"
peerDependencies:
Expand Down Expand Up @@ -2914,7 +2910,7 @@ __metadata:
languageName: node
linkType: hard

"eslint-plugin-import@npm:2.29.1, eslint-plugin-import@npm:^2.29.1":
"eslint-plugin-import@npm:2.29.1":
version: 2.29.1
resolution: "eslint-plugin-import@npm:2.29.1"
dependencies:
Expand All @@ -2941,7 +2937,7 @@ __metadata:
languageName: node
linkType: hard

"eslint-plugin-json-es@npm:1.6.0, eslint-plugin-json-es@npm:^1.6.0":
"eslint-plugin-json-es@npm:1.6.0":
version: 1.6.0
resolution: "eslint-plugin-json-es@npm:1.6.0"
dependencies:
Expand Down Expand Up @@ -3043,7 +3039,7 @@ __metadata:
languageName: node
linkType: hard

"eslint-plugin-rxjs@npm:5.0.3, eslint-plugin-rxjs@npm:^5.0.3":
"eslint-plugin-rxjs@npm:5.0.3":
version: 5.0.3
resolution: "eslint-plugin-rxjs@npm:5.0.3"
dependencies:
Expand Down Expand Up @@ -3072,15 +3068,6 @@ __metadata:
languageName: node
linkType: hard

"eslint-plugin-simple-import-sort@npm:^12.1.0":
version: 12.1.0
resolution: "eslint-plugin-simple-import-sort@npm:12.1.0"
peerDependencies:
eslint: ">=5.0.0"
checksum: 10c0/11e963683216e190b09bb6834b6978ca71d438d9413c52495e92493b0a68fc10268d7fd5815814496ab02fe7c018e4d5fd82866bf3ed5f95cff69628ca741102
languageName: node
linkType: hard

"eslint-plugin-vue@npm:9.28.0, eslint-plugin-vue@npm:^9.28.0":
version: 9.28.0
resolution: "eslint-plugin-vue@npm:9.28.0"
Expand Down

0 comments on commit db5b3ef

Please sign in to comment.