Skip to content

Commit

Permalink
fix: own rules, I guess
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCalzone committed Sep 17, 2024
1 parent bec0bf7 commit db57495
Show file tree
Hide file tree
Showing 45 changed files with 556 additions and 551 deletions.
36 changes: 25 additions & 11 deletions eslint.config.js → eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,30 @@

// @ts-check

import tseslint from "typescript-eslint";
import deprecation from "eslint-plugin-deprecation";
import unusedImports from "eslint-plugin-unused-imports";
import unicorn from "eslint-plugin-unicorn";
import zjs from "@zwave-js/eslint-plugin";
import unicorn from "eslint-plugin-unicorn";
import unusedImports from "eslint-plugin-unused-imports";
import jsonc from "jsonc-eslint-parser";
import tseslint from "typescript-eslint";

import { dirname } from "node:path";
import { fileURLToPath } from "node:url";
const __dirname = dirname(fileURLToPath(import.meta.url));

export default tseslint.config(
...tseslint.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
{
languageOptions: {
parserOptions: {
project: "./tsconfig.all.json",
project: "tsconfig.all.json",
tsconfigRootDir: __dirname,
},
},
linterOptions: {
reportUnusedDisableDirectives: true,
},
plugins: {
deprecation,
"unused-imports": unusedImports,
unicorn,
"@zwave-js": zjs,
Expand Down Expand Up @@ -123,6 +126,7 @@ export default tseslint.config(
{ allowArgumentsExplicitlyTypedAsAny: true },
],
"@typescript-eslint/no-this-alias": "off",
"@typescript-eslint/no-deprecated": "error",

// Prefer simple property access and declaration without quotes
"dot-notation": "off",
Expand All @@ -134,8 +138,7 @@ export default tseslint.config(
},
],
"quote-props": ["error", "as-needed"],
"deprecation/deprecation": "error",
"unused-imports/no-unused-imports-ts": "error",

"unused-imports/no-unused-imports": "error",

"unicorn/prefer-array-find": ["error", { checkFromLast: true }],
Expand Down Expand Up @@ -206,12 +209,23 @@ export default tseslint.config(
},
{
files: ["packages/config/config/devices/**/*.json"],
...zjs.configs.co
plugins: {
"@zwave-js": zjs,
},
languageOptions: {
parser: jsonc,
},
rules: {
"@zwave-js/consistent-device-configs": "error",
"@zwave-js/auto-unsigned": "error",
"@zwave-js/consistent-config-string-case": "error",
"@zwave-js/consistent-device-config-property-order": "error",
"@zwave-js/consistent-param-units": "error",
"@zwave-js/no-misspelled-names": "error",
"@zwave-js/no-surrounding-whitespace": "error",
"@zwave-js/no-unnecessary-min-max-value": "error",
"@zwave-js/no-useless-description": "error",
"@zwave-js/no-value-in-option-label": "error",
"@zwave-js/prefer-defaultvalue": "error",
},
}
},
);
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,9 @@
"dprint": "^0.47.2",
"esbuild": "0.21.5",
"esbuild-register": "^3.5.0",
"eslint": "^8.57.0",
"eslint-plugin-deprecation": "^2.0.0",
"eslint-plugin-unicorn": "^52.0.0",
"eslint-plugin-unused-imports": "^3.2.0",
"eslint": "^9.10.0",
"eslint-plugin-unicorn": "^55.0.0",
"eslint-plugin-unused-imports": "^4.1.4",
"execa": "^5.1.1",
"fs-extra": "^11.2.0",
"husky": "^9.1.5",
Expand All @@ -87,7 +86,7 @@
"ts-patch": "3.2.1",
"turbo": "1.13.4",
"typescript": "5.5.3",
"typescript-eslint": "^7.16.0",
"typescript-eslint": "^8.6.0",
"xml2js": "^0.6.2",
"zwave-js": "workspace:*"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/cc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"clean": "del-cli build/ \"*.tsbuildinfo\"",
"extract-api": "yarn api-extractor run",
"ts": "node -r esbuild-register --conditions=@@dev",
"lint:ts": "eslint --cache --ext .ts \"src/**/*.ts\"",
"lint:ts": "eslint --cache \"src/**/*.ts\"",
"lint:ts:fix": "yarn run lint:ts --fix",
"test:ts": "ava",
"test:dirty": "node -r ../../maintenance/esbuild-register.js ../maintenance/src/resolveDirtyTests.ts --run"
Expand Down
2 changes: 1 addition & 1 deletion packages/config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"extract-api": "yarn api-extractor run",
"lint:zwave": "yarn ts maintenance/lintConfigFiles.ts && eslint --cache --cache-location .eslintcache/config --ext .json \"config/devices/**/*.json\"",
"ts": "node -r esbuild-register --conditions=@@dev",
"lint:ts": "eslint --cache --cache-location .eslintcache/ts --ext .ts \"src/**/*.ts\"",
"lint:ts": "eslint --cache --cache-location .eslintcache/ts \"src/**/*.ts\"",
"lint:ts:fix": "yarn run lint:ts --fix",
"test:ts": "ava",
"test:dirty": "node -r ../../maintenance/esbuild-register.js ../maintenance/src/resolveDirtyTests.ts --run"
Expand Down
18 changes: 9 additions & 9 deletions packages/core/core.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -633,12 +633,12 @@ export function createLogMessagePrinter(shortTimestamps: boolean): Format;
// Warning: (ae-missing-release-tag) "createReflectionDecorator" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public
export function createReflectionDecorator<TBase extends Object, TArgs extends any[], TValue, TConstructor extends Constructor<TBase> = Constructor<TBase>>({ name, valueFromArgs, constructorLookupKey, }: CreateReflectionDecoratorOptions<TBase, TArgs, TValue, TConstructor>): ReflectionDecorator<TBase, TArgs, TValue, TConstructor>;
export function createReflectionDecorator<TBase extends object, TArgs extends any[], TValue, TConstructor extends Constructor<TBase> = Constructor<TBase>>({ name, valueFromArgs, constructorLookupKey, }: CreateReflectionDecoratorOptions<TBase, TArgs, TValue, TConstructor>): ReflectionDecorator<TBase, TArgs, TValue, TConstructor>;

// Warning: (ae-missing-release-tag) "CreateReflectionDecoratorOptions" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export interface CreateReflectionDecoratorOptions<TBase extends Object, TArgs extends any[], TValue, TConstructor extends Constructor<TBase> = Constructor<TBase>> {
export interface CreateReflectionDecoratorOptions<TBase extends object, TArgs extends any[], TValue, TConstructor extends Constructor<TBase> = Constructor<TBase>> {
constructorLookupKey?: false | ((target: TConstructor, ...args: TArgs) => string);
name: string;
valueFromArgs: (...args: TArgs) => TValue;
Expand All @@ -647,7 +647,7 @@ export interface CreateReflectionDecoratorOptions<TBase extends Object, TArgs ex
// Warning: (ae-missing-release-tag) "createReflectionDecoratorPair" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public
export function createReflectionDecoratorPair<TBase extends Object, TSuperArgs extends [any], TSubArgs extends [any], TConstructor extends Constructor<TBase> = Constructor<TBase>>({ superName, subName, }: CreateReflectionDecoratorPairOptions): ReflectionDecoratorPair<TBase, TSuperArgs, TSubArgs, TConstructor>;
export function createReflectionDecoratorPair<TBase extends object, TSuperArgs extends [any], TSubArgs extends [any], TConstructor extends Constructor<TBase> = Constructor<TBase>>({ superName, subName, }: CreateReflectionDecoratorPairOptions): ReflectionDecoratorPair<TBase, TSuperArgs, TSubArgs, TConstructor>;

// Warning: (ae-missing-release-tag) "CreateReflectionDecoratorPairOptions" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
Expand All @@ -660,7 +660,7 @@ export interface CreateReflectionDecoratorPairOptions {
// Warning: (ae-missing-release-tag) "createSimpleReflectionDecorator" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public
export function createSimpleReflectionDecorator<TBase extends Object, TArgs extends [any], TConstructor extends Constructor<TBase> = Constructor<TBase>>({ name, }: CreateSimpleReflectionDecoratorOptions): SimpleReflectionDecorator<TBase, TArgs, TConstructor>;
export function createSimpleReflectionDecorator<TBase extends object, TArgs extends [any], TConstructor extends Constructor<TBase> = Constructor<TBase>>({ name, }: CreateSimpleReflectionDecoratorOptions): SimpleReflectionDecorator<TBase, TArgs, TConstructor>;

// Warning: (ae-missing-release-tag) "CreateSimpleReflectionDecoratorOptions" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
Expand All @@ -672,7 +672,7 @@ export interface CreateSimpleReflectionDecoratorOptions {
// Warning: (ae-missing-release-tag) "createValuelessReflectionDecorator" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public
export function createValuelessReflectionDecorator<TBase extends Object>({ name, }: CreateValuelessReflectionDecoratorOptions): ValuelessReflectionDecorator<TBase>;
export function createValuelessReflectionDecorator<TBase extends object>({ name, }: CreateValuelessReflectionDecoratorOptions): ValuelessReflectionDecorator<TBase>;

// Warning: (ae-missing-release-tag) "CreateValuelessReflectionDecoratorOptions" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
Expand Down Expand Up @@ -2822,7 +2822,7 @@ export type QRProvisioningInformation = {
// Warning: (ae-missing-release-tag) "ReflectionDecorator" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export interface ReflectionDecorator<TBase extends Object, TArgs extends any[], TValue, TConstructor extends Constructor<TBase> = Constructor<TBase>> {
export interface ReflectionDecorator<TBase extends object, TArgs extends any[], TValue, TConstructor extends Constructor<TBase> = Constructor<TBase>> {
decorator: <TTarget extends TBase>(...args: TArgs) => TypedClassDecorator<TTarget>;
lookupConstructorByKey: (key: string) => TConstructor | undefined;
lookupConstructorByValue: (value: TValue) => TConstructor | undefined;
Expand All @@ -2833,7 +2833,7 @@ export interface ReflectionDecorator<TBase extends Object, TArgs extends any[],
// Warning: (ae-missing-release-tag) "ReflectionDecoratorPair" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export interface ReflectionDecoratorPair<TBase extends Object, TSuperArgs extends [any], TSubArgs extends [any], TConstructor extends Constructor<TBase> = Constructor<TBase>> {
export interface ReflectionDecoratorPair<TBase extends object, TSuperArgs extends [any], TSubArgs extends [any], TConstructor extends Constructor<TBase> = Constructor<TBase>> {
lookupSubConstructor: (...args: [...TSuperArgs, ...TSubArgs]) => TConstructor | undefined;
lookupSubValue: (target: TBase) => TSubArgs[0] | undefined;
lookupSubValueStatic: (constr: Function) => TSubArgs[0] | undefined;
Expand Down Expand Up @@ -3259,7 +3259,7 @@ export interface SetValueOptions {
// Warning: (ae-missing-release-tag) "SimpleReflectionDecorator" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export interface SimpleReflectionDecorator<TBase extends Object, TArgs extends [any], TConstructor extends Constructor<TBase> = Constructor<TBase>> {
export interface SimpleReflectionDecorator<TBase extends object, TArgs extends [any], TConstructor extends Constructor<TBase> = Constructor<TBase>> {
decorator: <TTarget extends TBase>(...args: TArgs) => TypedClassDecorator<TTarget>;
lookupConstructor: (...args: TArgs) => TConstructor | undefined;
lookupValue: (target: TBase) => TArgs[0] | undefined;
Expand Down Expand Up @@ -3654,7 +3654,7 @@ export function valueIdToString(valueID: ValueID): string;
// Warning: (ae-missing-release-tag) "ValuelessReflectionDecorator" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export interface ValuelessReflectionDecorator<TBase extends Object> {
export interface ValuelessReflectionDecorator<TBase extends object> {
decorator: <TTarget extends TBase>() => TypedClassDecorator<TTarget>;
isDecorated: (target: TBase) => boolean;
isDecoratedStatic: (constr: Function) => boolean;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"build": "tsc -b tsconfig.build.json --pretty",
"clean": "del-cli build/ \"*.tsbuildinfo\"",
"extract-api": "yarn api-extractor run",
"lint:ts": "eslint --cache --ext .ts \"src/**/*.ts\"",
"lint:ts": "eslint --cache \"src/**/*.ts\"",
"lint:ts:fix": "yarn run lint:ts --fix",
"test:ts": "ava",
"test:dirty": "node -r ../../maintenance/esbuild-register.js ../maintenance/src/resolveDirtyTests.ts --run"
Expand Down
40 changes: 12 additions & 28 deletions packages/core/src/util/decorators.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/* eslint-disable @typescript-eslint/no-unsafe-function-type */
import type { TypedClassDecorator } from "@zwave-js/shared";
import "reflect-metadata";

type Constructor<T> = new (...args: any[]) => T;

export interface ReflectionDecorator<
// eslint-disable-next-line @typescript-eslint/ban-types
TBase extends Object,
TBase extends object,
TArgs extends any[],
TValue,
TConstructor extends Constructor<TBase> = Constructor<TBase>,
Expand All @@ -17,7 +17,6 @@ export interface ReflectionDecorator<
/** Looks up the value which was assigned to the target class by the decorator, using a class instance */
lookupValue: (target: TBase) => TValue | undefined;
/** Looks up the value which was assigned to the target class by the decorator, using the class itself */
// eslint-disable-next-line @typescript-eslint/ban-types
lookupValueStatic: (constr: Function) => TValue | undefined;
/** Looks up the class constructor for a given value. This can only be used if the value does not need to be transformed using `constructorLookupKey`. */
lookupConstructorByValue: (value: TValue) => TConstructor | undefined;
Expand All @@ -26,8 +25,7 @@ export interface ReflectionDecorator<
}

export interface CreateReflectionDecoratorOptions<
// eslint-disable-next-line @typescript-eslint/ban-types
TBase extends Object,
TBase extends object,
TArgs extends any[],
TValue,
TConstructor extends Constructor<TBase> = Constructor<TBase>,
Expand All @@ -47,8 +45,7 @@ export interface CreateReflectionDecoratorOptions<

/** Creates a reflection decorator and corresponding methods for reverse lookup of values and constructors */
export function createReflectionDecorator<
// eslint-disable-next-line @typescript-eslint/ban-types
TBase extends Object,
TBase extends object,
TArgs extends any[],
TValue,
TConstructor extends Constructor<TBase> = Constructor<TBase>,
Expand Down Expand Up @@ -147,8 +144,7 @@ export function createReflectionDecorator<
}

export interface SimpleReflectionDecorator<
// eslint-disable-next-line @typescript-eslint/ban-types
TBase extends Object,
TBase extends object,
TArgs extends [any],
TConstructor extends Constructor<TBase> = Constructor<TBase>,
> {
Expand All @@ -161,7 +157,6 @@ export interface SimpleReflectionDecorator<
lookupValue: (target: TBase) => TArgs[0] | undefined;

/** Looks up the value which was assigned to the target class by the decorator, using the class itself */
// eslint-disable-next-line @typescript-eslint/ban-types
lookupValueStatic: (constr: Function) => TArgs[0] | undefined;

/** Looks up the super class constructor for a given value. */
Expand All @@ -177,8 +172,7 @@ export interface CreateSimpleReflectionDecoratorOptions {
* Like {@link createReflectionDecorator}, but for single-value decorators. This has the advantage that the returned functions can be reused easier with named args.
*/
export function createSimpleReflectionDecorator<
// eslint-disable-next-line @typescript-eslint/ban-types
TBase extends Object,
TBase extends object,
TArgs extends [any],
TConstructor extends Constructor<TBase> = Constructor<TBase>,
>({
Expand Down Expand Up @@ -209,8 +203,7 @@ export function createSimpleReflectionDecorator<
}

export interface ValuelessReflectionDecorator<
// eslint-disable-next-line @typescript-eslint/ban-types
TBase extends Object,
TBase extends object,
> {
/** The decorator which is used to decorate the super class */
decorator: <TTarget extends TBase>() => TypedClassDecorator<TTarget>;
Expand All @@ -219,7 +212,6 @@ export interface ValuelessReflectionDecorator<
isDecorated: (target: TBase) => boolean;

/** Checks if the target class was decorated by this decorator, using the class itself */
// eslint-disable-next-line @typescript-eslint/ban-types
isDecoratedStatic: (constr: Function) => boolean;
}

Expand All @@ -232,8 +224,7 @@ export interface CreateValuelessReflectionDecoratorOptions {
* Like {@link createReflectionDecorator}, but for valueless decorators.
*/
export function createValuelessReflectionDecorator<
// eslint-disable-next-line @typescript-eslint/ban-types
TBase extends Object,
TBase extends object,
>({
name,
}: CreateValuelessReflectionDecoratorOptions): ValuelessReflectionDecorator<
Expand All @@ -247,7 +238,6 @@ export function createValuelessReflectionDecorator<
const ret: ValuelessReflectionDecorator<TBase> = {
decorator: decorator.decorator,
isDecorated: (target: TBase) => !!decorator.lookupValue(target),
// eslint-disable-next-line @typescript-eslint/ban-types
isDecoratedStatic: (constr: Function) =>
!!decorator.lookupValueStatic(constr),
};
Expand All @@ -256,8 +246,7 @@ export function createValuelessReflectionDecorator<
}

export interface ReflectionDecoratorPair<
// eslint-disable-next-line @typescript-eslint/ban-types
TBase extends Object,
TBase extends object,
TSuperArgs extends [any],
TSubArgs extends [any],
TConstructor extends Constructor<TBase> = Constructor<TBase>,
Expand All @@ -278,10 +267,8 @@ export interface ReflectionDecoratorPair<
lookupSubValue: (target: TBase) => TSubArgs[0] | undefined;

/** Looks up the value which was assigned to the target super class by the decorator, using the class itself */
// eslint-disable-next-line @typescript-eslint/ban-types
lookupSuperValueStatic: (constr: Function) => TSuperArgs[0] | undefined;
/** Looks up the value which was assigned to the target sub class by the decorator, using the class itself */
// eslint-disable-next-line @typescript-eslint/ban-types
lookupSubValueStatic: (constr: Function) => TSubArgs[0] | undefined;

/** Looks up the super class constructor for a given value. */
Expand All @@ -304,8 +291,7 @@ export interface CreateReflectionDecoratorPairOptions {
* This pair is meant to decorate a super class and several of its subclasses
*/
export function createReflectionDecoratorPair<
// eslint-disable-next-line @typescript-eslint/ban-types
TBase extends Object,
TBase extends object,
TSuperArgs extends [any],
TSubArgs extends [any],
TConstructor extends Constructor<TBase> = Constructor<TBase>,
Expand Down Expand Up @@ -370,8 +356,7 @@ export function createReflectionDecoratorPair<
}

// export interface PropertyReflectionDecorator<
// // eslint-disable-next-line @typescript-eslint/ban-types
// TTarget extends Object,
// // TTarget extends object,
// TArgs extends any[],
// TValue,
// > {
Expand All @@ -393,8 +378,7 @@ export function createReflectionDecoratorPair<

// /** Creates a reflection decorator for a class property and the corresponding method for reverse lookup of defined values */
// export function createPropertyReflectionDecorator<
// // eslint-disable-next-line @typescript-eslint/ban-types
// TTarget extends Object,
// // TTarget extends object,
// TArgs extends any[],
// TValue,
// >({
Expand Down
11 changes: 7 additions & 4 deletions packages/eslint-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"private": true,
"keywords": [],
"type": "module",
"main": "build/index.js",
"module": "build/index.js",
"files": [
"build/**/*.js"
Expand Down Expand Up @@ -32,14 +33,16 @@
"build": "tsc -b tsconfig.build.json --pretty",
"bootstrap": "yarn build",
"clean": "del-cli build/ \"*.tsbuildinfo\"",
"lint:ts": "eslint --cache --ext .ts \"src/**/*.ts\"",
"lint:ts": "eslint --cache \"src/**/*.ts\"",
"lint:ts:fix": "yarn run lint:ts --fix"
},
"devDependencies": {
"@types/eslint": "^8.56.10",
"@typescript-eslint/utils": "^7.13.0",
"@types/eslint": "^9.6.1",
"@typescript-eslint/utils": "^8.6.0",
"@zwave-js/core": "workspace:*",
"eslint": "^8.57.0",
"eslint": "^9.10.0",
"eslint-compat-utils": "^0.5.1",
"eslint-plugin-jsonc": "^2.16.0",
"typescript": "5.5.3"
}
}
Loading

0 comments on commit db57495

Please sign in to comment.