Skip to content

Commit

Permalink
adjust rules
Browse files Browse the repository at this point in the history
Signed-off-by: Kangrui Johann Ye <[email protected]>
  • Loading branch information
strawberry-choco committed Oct 11, 2024
1 parent b9956fc commit 6e27338
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 13 deletions.
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;
}

0 comments on commit 6e27338

Please sign in to comment.