Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade ESLint to v9 #254

Merged
merged 2 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions .eslintrc.js

This file was deleted.

38 changes: 38 additions & 0 deletions eslint.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// @ts-check

const foxglove = require("@foxglove/eslint-plugin");
const globals = require("globals");
const tseslint = require("typescript-eslint");

module.exports = tseslint.config(
{
ignores: ["**/dist"],
},
{
languageOptions: {
globals: {
...globals.node,
},
},
},
{
files: ["**/*.ts", "**/*.tsx"],
languageOptions: {
parserOptions: {
project: "tsconfig.json",
tsconfigRootDir: __dirname,
},
},
},
...foxglove.configs.base,
...foxglove.configs.jest,
...foxglove.configs.typescript.map((config) => ({
...config,
files: ["**/*.ts", "**/*.tsx"],
})),
{
rules: {
"@foxglove/prefer-hash-private": "off", // may require a version bump when enabling & fixing this
},
},
);
20 changes: 7 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,14 @@
},
"packageManager": "[email protected]",
"devDependencies": {
"@foxglove/eslint-plugin": "^0.22.1",
"@types/jest": "^29.5.2",
"@typescript-eslint/eslint-plugin": "^5.60.0",
"@typescript-eslint/parser": "^7.2.0",
"eslint": "8.52.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-es": "^4.1.0",
"eslint-plugin-filenames": "^1.3.2",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jest": "^28.8.3",
"eslint-plugin-prettier": "^4.2.1",
"@foxglove/eslint-plugin": "2.0.0",
"@types/jest": "29.5.2",
"eslint": "9.14.0",
"globals": "15.12.0",
"jest": "29.6.4",
"prettier": "2.7.1",
"prettier": "3.3.3",
"ts-jest": "29.1.4",
"typescript": "5.6.3"
"typescript": "5.6.3",
"typescript-eslint": "8.13.0"
}
}
13 changes: 0 additions & 13 deletions packages/omgidl-parser/.eslintrc.js

This file was deleted.

38 changes: 38 additions & 0 deletions packages/omgidl-parser/eslint.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// @ts-check

const foxglove = require("@foxglove/eslint-plugin");
const globals = require("globals");
const tseslint = require("typescript-eslint");

module.exports = tseslint.config(
{
ignores: ["**/dist"],
},
{
languageOptions: {
globals: {
...globals.node,
},
},
},
{
files: ["**/*.ts", "**/*.tsx"],
languageOptions: {
parserOptions: {
project: "tsconfig.json",
tsconfigRootDir: __dirname,
},
},
},
...foxglove.configs.base,
...foxglove.configs.jest,
...foxglove.configs.typescript.map((config) => ({
...config,
files: ["**/*.ts", "**/*.tsx"],
})),
{
rules: {
"@foxglove/prefer-hash-private": "off", // may require a version bump when enabling & fixing this
},
},
);
4 changes: 2 additions & 2 deletions packages/omgidl-parser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
"scripts": {
"clean": "rimraf dist",
"build": "yarn clean && webpack",
"lint": "eslint --report-unused-disable-directives --fix .",
"lint:ci": "eslint --report-unused-disable-directives .",
"lint": "eslint --fix .",
"lint:ci": "eslint .",
"prepack": "yarn build",
"prepublishOnly": "yarn lint:ci && yarn test",
"test": "jest"
Expand Down
1 change: 1 addition & 0 deletions packages/omgidl-parser/src/IDLNodes/ConstantIDLNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export class ConstantIDLNode extends IDLNode<ConstantASTNode> implements IConsta
return this.referencedEnumNode;
}

// eslint-disable-next-line @typescript-eslint/class-literal-property-style
get isConstant(): true {
return true;
}
Expand Down
7 changes: 2 additions & 5 deletions packages/omgidl-parser/src/IDLNodes/EnumIDLNode.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import { IDLNode, toScopedIdentifier } from "./IDLNode";
import { AnyIDLNode, IConstantIDLNode, IEnumIDLNode } from "./interfaces";
import { IConstantIDLNode, IEnumIDLNode } from "./interfaces";
import { EnumASTNode } from "../astTypes";
import { IDLMessageDefinition } from "../types";

/** Class used to resolve an Enum ASTNode to an IDLMessageDefinition */

export class EnumIDLNode extends IDLNode<EnumASTNode> implements IEnumIDLNode {
constructor(scopePath: string[], astNode: EnumASTNode, idlMap: Map<string, AnyIDLNode>) {
super(scopePath, astNode, idlMap);
}

// eslint-disable-next-line @typescript-eslint/class-literal-property-style
get type(): string {
return "uint32";
}
Expand Down
4 changes: 0 additions & 4 deletions packages/omgidl-parser/src/IDLNodes/ModuleIDLNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ import { ModuleASTNode } from "../astTypes";
import { IDLMessageDefinition, IDLMessageDefinitionField } from "../types";

export class ModuleIDLNode extends IDLNode<ModuleASTNode> implements IModuleIDLNode {
constructor(scopePath: string[], astNode: ModuleASTNode, idlMap: Map<string, AnyIDLNode>) {
super(scopePath, astNode, idlMap);
}

/** Writes out module to message definition that contains only its directly descendent constant definitions */
toIDLMessageDefinition(): IDLMessageDefinition | undefined {
const definitions: IDLMessageDefinitionField[] = this.definitions.flatMap((def) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export abstract class ReferenceTypeIDLNode<T extends TypedefASTNode | StructMemb
if (this.typeNeedsResolution) {
const parent = this.typeRef();
if (parent.declarator === "typedef") {
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
isArray ||= parent.isArray;
}
}
Expand Down
6 changes: 1 addition & 5 deletions packages/omgidl-parser/src/IDLNodes/StructIDLNode.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { IDLNode } from "./IDLNode";
import { StructMemberIDLNode } from "./StructMemberIDLNode";
import { AnyIDLNode, IStructIDLNode } from "./interfaces";
import { IStructIDLNode } from "./interfaces";
import { StructASTNode } from "../astTypes";
import { IDLMessageDefinition } from "../types";

export class StructIDLNode extends IDLNode<StructASTNode> implements IStructIDLNode {
constructor(scopePath: string[], astNode: StructASTNode, idlMap: Map<string, AnyIDLNode>) {
super(scopePath, astNode, idlMap);
}

get type(): string {
return this.astNode.name;
}
Expand Down
6 changes: 1 addition & 5 deletions packages/omgidl-parser/src/IDLNodes/StructMemberIDLNode.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ReferenceTypeIDLNode } from "./ReferenceTypeIDLNode";
import { AnyIDLNode, IStructMemberIDLNode } from "./interfaces";
import { IStructMemberIDLNode } from "./interfaces";
import { StructMemberASTNode } from "../astTypes";
import { normalizeType } from "../primitiveTypes";
import { IDLMessageDefinitionField } from "../types";
Expand All @@ -8,10 +8,6 @@ export class StructMemberIDLNode
extends ReferenceTypeIDLNode<StructMemberASTNode>
implements IStructMemberIDLNode
{
constructor(scopePath: string[], node: StructMemberASTNode, idlMap: Map<string, AnyIDLNode>) {
super(scopePath, node, idlMap);
}

/** Writes out ASTNode as a fully resolved IDL message definition */
toIDLMessageDefinitionField(): IDLMessageDefinitionField {
const msgDefinitionField: IDLMessageDefinitionField = {
Expand Down
9 changes: 2 additions & 7 deletions packages/omgidl-parser/src/IDLNodes/TypedefIDLNode.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { ReferenceTypeIDLNode } from "./ReferenceTypeIDLNode";
import { AnyIDLNode, ITypedefIDLNode } from "./interfaces";
import { ITypedefIDLNode } from "./interfaces";
import { TypedefASTNode } from "../astTypes";

export class TypedefIDLNode
extends ReferenceTypeIDLNode<TypedefASTNode>
implements ITypedefIDLNode
{
constructor(scopePath: string[], astNode: TypedefASTNode, idlMap: Map<string, AnyIDLNode>) {
super(scopePath, astNode, idlMap);
}
}
implements ITypedefIDLNode {}
1 change: 1 addition & 0 deletions packages/omgidl-parser/src/IDLNodes/UnionIDLNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export class UnionIDLNode extends IDLNode<UnionASTNode> implements IUnionIDLNode
return this.astNode.name;
}

// eslint-disable-next-line @typescript-eslint/class-literal-property-style
get isComplex(): boolean {
return true;
}
Expand Down
4 changes: 3 additions & 1 deletion packages/omgidl-parser/src/processIDL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ const makeIDLNode = (
function traverseIDL(path: AnyASTNode[], processNode: (path: AnyASTNode[]) => void) {
const currNode = path[path.length - 1]!;
if ("definitions" in currNode) {
currNode.definitions.forEach((n) => traverseIDL([...path, n], processNode));
currNode.definitions.forEach((n) => {
traverseIDL([...path, n], processNode);
});
}
processNode(path);
}
13 changes: 0 additions & 13 deletions packages/omgidl-serialization/.eslintrc.js

This file was deleted.

38 changes: 38 additions & 0 deletions packages/omgidl-serialization/eslint.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// @ts-check

const foxglove = require("@foxglove/eslint-plugin");
const globals = require("globals");
const tseslint = require("typescript-eslint");

module.exports = tseslint.config(
{
ignores: ["**/dist"],
},
{
languageOptions: {
globals: {
...globals.node,
},
},
},
{
files: ["**/*.ts", "**/*.tsx"],
languageOptions: {
parserOptions: {
project: "tsconfig.json",
tsconfigRootDir: __dirname,
},
},
},
...foxglove.configs.base,
...foxglove.configs.jest,
...foxglove.configs.typescript.map((config) => ({
...config,
files: ["**/*.ts", "**/*.tsx"],
})),
{
rules: {
"@foxglove/prefer-hash-private": "off", // may require a version bump when enabling & fixing this
},
},
);
4 changes: 2 additions & 2 deletions packages/omgidl-serialization/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
"scripts": {
"clean": "rm -rf dist tsconfig.build.tsbuildinfo",
"build": "tsc -b ./tsconfig.build.json",
"lint:ci": "eslint --report-unused-disable-directives .",
"lint": "eslint --report-unused-disable-directives --fix .",
"lint:ci": "eslint .",
"lint": "eslint --fix .",
"prepack": "yarn build",
"prepublishOnly": "yarn lint:ci && yarn test",
"test": "jest"
Expand Down
9 changes: 6 additions & 3 deletions packages/omgidl-serialization/src/DeserializationInfoCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export type FieldDeserializationInfo<

export class DeserializationInfoCache {
#definitions: Map<string, IDLMessageDefinition>;
#complexDeserializationInfo: Map<string, ComplexDeserializationInfo> = new Map();
#complexDeserializationInfo = new Map<string, ComplexDeserializationInfo>();

constructor(definitions: IDLMessageDefinition[]) {
this.#definitions = new Map<string, IDLMessageDefinition>(
Expand Down Expand Up @@ -158,12 +158,12 @@ export class DeserializationInfoCache {
type: "struct",
...getHeaderNeeds(definition),
definition,
fields: definition.definitions.reduce(
fields: definition.definitions.reduce<FieldDeserializationInfo[]>(
(fieldsAccum, fieldDef) =>
fieldDef.isConstant === true
? fieldsAccum
: fieldsAccum.concat(this.buildFieldDeserInfo(fieldDef)),
[] as FieldDeserializationInfo[],
[],
),
};

Expand Down Expand Up @@ -315,13 +315,15 @@ export class DeserializationInfoCache {
}
const defaultCaseDeserInfo = this.buildFieldDeserInfo(defaultCase);
defaultMessage[defaultCaseDeserInfo.name] = this.getFieldDefault(defaultCaseDeserInfo);
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
} else if (deserInfo.type === "struct") {
for (const field of deserInfo.fields) {
if (!field.isOptional) {
defaultMessage[field.name] = this.getFieldDefault(field);
}
}
}
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (defaultMessage == undefined) {
throw new Error(`Unrecognized complex type ${deserInfo.type as string}`);
}
Expand Down Expand Up @@ -476,6 +478,7 @@ function getDefinitionId(definition: IDLMessageDefinitionField): number | undefi
}

const id = annotations.id;
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (id != undefined && id.type === "const-param" && typeof id.value === "number") {
return id.value;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/omgidl-serialization/src/MessageReader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ describe("MessageReader", () => {
[
`struct a {double sample; };`,
"a",
// eslint-disable-next-line @typescript-eslint/no-loss-of-precision
// eslint-disable-next-line no-loss-of-precision
new Uint8Array(Float64Array.of(0.123456789121212121212).buffer),
// eslint-disable-next-line @typescript-eslint/no-loss-of-precision
// eslint-disable-next-line no-loss-of-precision
{ sample: 0.123456789121212121212 },
],
[
Expand Down
2 changes: 2 additions & 0 deletions packages/omgidl-serialization/src/MessageReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export class MessageReader<T = unknown> {

// We template on R here for call site type information if the class type information T is not
// known or available
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
readMessage<R = T>(buffer: ArrayBufferView): R {
const reader = new CdrReader(buffer);
const usesDelimiterHeader = reader.usesDelimiterHeader;
Expand Down Expand Up @@ -275,6 +276,7 @@ export class MessageReader<T = unknown> {
} else {
return deser(reader, arrayLengths[0]!);
}
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
} else if (field.typeDeserInfo.type === "primitive") {
return field.typeDeserInfo.deserialize(
reader,
Expand Down
Loading