Skip to content

Commit

Permalink
Merge pull request #1076 from y-lohse/update/2.2.5
Browse files Browse the repository at this point in the history
Update eslint
  • Loading branch information
smwhr authored Aug 3, 2024
2 parents 926a6ab + 16c2fbd commit b5dd123
Show file tree
Hide file tree
Showing 14 changed files with 53 additions and 25 deletions.
4 changes: 4 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,21 @@ module.exports = {
"@typescript-eslint/no-namespace": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-argument": "off",
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/no-unsafe-return": "off",
"@typescript-eslint/restrict-plus-operands": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/restrict-template-expressions": "off",
"@typescript-eslint/no-base-to-string": "off",
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/unbound-method": "off",
"@typescript-eslint/no-this-alias": "off",
"@typescript-eslint/no-inferrable-types": "off",
"@typescript-eslint/no-unnecessary-type-assertion": "off",
"@typescript-eslint/no-redundant-type-constituents": "off",
"@typescript-eslint/no-unsafe-enum-comparison": "off",
"prefer-const": "off",
"prefer-spread": "off",
"prefer-rest-params": "off",
Expand Down
33 changes: 21 additions & 12 deletions src/compiler/Parser/InkParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1594,17 +1594,17 @@ export class InkParser extends StringParser {
return divertTarget;
}

let prefixOp: Expression = this.OneOf([
let prefixOp: string = this.OneOf([
this.String("-"),
this.String("!"),
]) as Expression;
]) as string;

// Don't parse like the string rules above, in case its actually
// a variable that simply starts with "not", e.g. "notable".
// This rule uses the Identifier rule, which will scan as much text
// as possible before returning.
if (prefixOp === null) {
prefixOp = this.Parse(this.ExpressionNot) as Expression;
prefixOp = this.Parse(this.ExpressionNot) as string;
}

this.Whitespace();
Expand All @@ -1627,7 +1627,7 @@ export class InkParser extends StringParser {
if (expr === null) {
return null;
} else if (prefixOp !== null) {
expr = UnaryExpression.WithInner(expr, prefixOp as any) as Expression;
expr = UnaryExpression.WithInner(expr, prefixOp) as Expression;
}

this.Whitespace();
Expand Down Expand Up @@ -1746,12 +1746,14 @@ export class InkParser extends StringParser {

this.Whitespace();

const args = this.Parse(this.ExpressionFunctionCallArguments);
const args = this.Parse(
this.ExpressionFunctionCallArguments
) as Expression[];
if (args === null) {
return null;
}

return new FunctionCall(iden as Identifier, args as any);
return new FunctionCall(iden as Identifier, args);
};

public readonly ExpressionFunctionCallArguments = (): Expression[] | null => {
Expand Down Expand Up @@ -2383,7 +2385,10 @@ export class InkParser extends StringParser {
// Multiple newlines on the output will be removed, so there will be no "leak" for
// long running calculations. It's disappointingly messy though :-/
if (result.Find(FunctionCall)() !== null) {
result = new ContentList(result as any, new Text("\n"));
result = new ContentList(
result as unknown as ParsedObject[],
new Text("\n")
);
}

this.Expect(this.EndOfLine, "end of line", this.SkipToNextLine);
Expand Down Expand Up @@ -2662,7 +2667,7 @@ export class InkParser extends StringParser {

let contentList = asOrNull(logic, ContentList);
if (!contentList) {
contentList = new ContentList(logic as any);
contentList = new ContentList(logic as unknown as ParsedObject[]);
}

this.Whitespace();
Expand Down Expand Up @@ -2735,7 +2740,7 @@ export class InkParser extends StringParser {
this.InnerExpression,
];

let wasTagActiveAtStartOfScope = this.tagActive;
//let wasTagActiveAtStartOfScope = this.tagActive;

// Adapted from "OneOf" structuring rule except that in
// order for the rule to succeed, it has to maximally
Expand Down Expand Up @@ -2856,7 +2861,9 @@ export class InkParser extends StringParser {
case SequenceType.Cycle:
case SequenceType.Stopping:
case SequenceType.Shuffle:
// eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison
case SequenceType.Shuffle | SequenceType.Stopping:
// eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison
case SequenceType.Shuffle | SequenceType.Once:
break;
default:
Expand Down Expand Up @@ -2998,10 +3005,10 @@ export class InkParser extends StringParser {
justHadContent = false;
} else {
// Real content
const content = contentOrPipe as any;
const content = contentOrPipe as unknown as ParsedObject[];
if (content === null) {
this.Error(
`Expected content, but got ${contentOrPipe} (this is an ink compiler bug!)`
`Expected content, but got ${contentOrPipe as unknown as string} (this is an ink compiler bug!)`
);
} else {
result.push(new ContentList(content));
Expand Down Expand Up @@ -3124,7 +3131,9 @@ export class InkParser extends StringParser {
};

public readonly GenerateStatementLevelRules = () => {
const levels : StatementLevel[] = Object.values(StatementLevel) as StatementLevel[];
const levels: StatementLevel[] = Object.values(
StatementLevel
) as StatementLevel[];

this._statementRulesAtLevel = "f"
.repeat(levels.length)
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/Parser/ParsedHierarchy/Divert/Divert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ export class Divert extends ParsedObject {
const externalName: string | null = this.target
? this.target.firstComponent
: null;
const external = context.externals.get(externalName as any);
const external = context.externals.get(externalName as string);
if (!external) {
throw new Error("external not found");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ export class BinaryExpression extends Expression {
public readonly leftExpression: Expression;
public readonly rightExpression: Expression;

constructor(left: Expression, right: Expression, public opName: string) {
constructor(
left: Expression,
right: Expression,
public opName: string
) {
super();

this.leftExpression = this.AddContent(left) as Expression;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export abstract class Expression extends ParsedObject {
return "Expression";
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
public Equals(obj: ParsedObject): boolean {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ export class UnaryExpression extends Expression {
return unary;
};

constructor(inner: Expression, public readonly op: string) {
constructor(
inner: Expression,
public readonly op: string
) {
super();

this.innerExpression = this.AddContent(inner) as Expression;
Expand Down
1 change: 1 addition & 0 deletions src/compiler/Parser/ParsedHierarchy/Flow/FlowBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export abstract class FlowBase extends ParsedObject implements INamedContent {
return finalContent;
};

// eslint-disable-next-line @typescript-eslint/no-unused-vars
public PreProcessTopLevelObjects(_: ParsedObject[]): void {
// empty by default, used by Story to process included file references
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export class VariableAssignment extends ParsedObject {
this.isGlobalDeclaration
? "VAR"
: this.isNewTemporaryDeclaration
? "~ temp"
: ""
? "~ temp"
: ""
} ${this.variableName}`;
}
2 changes: 2 additions & 0 deletions src/engine/ListDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ export class ListDefinition {
item = InkListItem.Null;
return { result: item, exists: false };
}

public TryGetValueForItem(
item: InkListItem,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
/* out */ intVal: number
): TryGetResult<number> {
if (!item.itemName) return { result: 0, exists: false };
Expand Down
2 changes: 1 addition & 1 deletion src/engine/SimpleJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ export namespace SimpleJson {
}
}

private get currentCollection() : Record<string, any> | null {
private get currentCollection(): Record<string, any> | null {
if (this._collectionStack.length > 0) {
return this._collectionStack[this._collectionStack.length - 1];
} else {
Expand Down
1 change: 1 addition & 0 deletions src/engine/TypeAssertion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export function isEquatable(type: any) {

function unsafeTypeAssertion<T>(
obj: any,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
type: (new () => T) | (Function & { prototype: T })
) {
return obj as T;
Expand Down
2 changes: 1 addition & 1 deletion src/engine/Value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export abstract class AbstractValue extends InkObject {
}

export abstract class Value<
T extends { toString: () => string }
T extends { toString: () => string },
> extends AbstractValue {
public value: T | null;

Expand Down
14 changes: 8 additions & 6 deletions src/tests/specs/inkjs/engine/Integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ describe("Integration", () => {
context.story.allowExternalFunctionFallbacks = false;
context.story.ChoosePathString("integration.external");

const externalSpy = jest.fn(a => a).mockName("external function spy");
const externalSpy = jest.fn((a) => a).mockName("external function spy");
context.story.BindExternalFunction("fn_ext", externalSpy);
context.story.BindExternalFunction("gameInc", () => undefined);

Expand All @@ -230,11 +230,13 @@ describe("Integration", () => {
it("should handle callstack changes", () => {
context.story.allowExternalFunctionFallbacks = false;

const externalSpy = jest.fn(x => {
x++;
x = parseInt(context.story.EvaluateFunction("inkInc", [x]));
return x;
}).mockName("external function spy");
const externalSpy = jest
.fn((x) => {
x++;
x = parseInt(context.story.EvaluateFunction("inkInc", [x]));
return x;
})
.mockName("external function spy");

context.story.BindExternalFunction("fn_ext", () => undefined);
context.story.BindExternalFunction("gameInc", externalSpy);
Expand Down
1 change: 1 addition & 0 deletions src/tests/specs/setupTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export {};

declare global {
namespace jest {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
interface Matchers<R> {
toContainStringContaining(expected: string): CustomMatcherResult;
}
Expand Down

0 comments on commit b5dd123

Please sign in to comment.