Skip to content

Commit

Permalink
chore(js): fix eslint warnings (#157)
Browse files Browse the repository at this point in the history
  • Loading branch information
rhamzeh authored Feb 14, 2024
2 parents d904ead + ad951c4 commit 93175fd
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 26 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/main-js.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ jobs:
- name: Audit dependencies
run: make audit-js

- name: Run Prettier
run: make format-js

- name: Run eslint
- name: Run eslint and prettier
run: make lint-js

build:
Expand Down
4 changes: 2 additions & 2 deletions pkg/js/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ test: init-deps
npm run test

lint: init-deps
npm run lint
npm run lint;npm run format:check

audit: init-deps
npm audit

format: init-deps
npm run format:fix
npm run lint:fix;npm run format:fix

all-tests: audit lint test
npx madge --circular --exclude '^dist|^gen' . --extensions ts,js
6 changes: 3 additions & 3 deletions pkg/js/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * as validator from './validator';
export * as transformer from './transformer';
export * as errors from './errors';
export * as validator from "./validator";
export * as transformer from "./transformer";
export * as errors from "./errors";
2 changes: 1 addition & 1 deletion pkg/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"postpublish": "rm -f README.md LICENSE",
"test": "jest --config ./jest.config.js",
"typecheck": "tsc --skipLibCheck",
"lint": "eslint -c .eslintrc.js --ext .ts",
"lint": "eslint . -c .eslintrc.js --ext .ts",
"lint:fix": "npm run lint -- --fix",
"format:check": "prettier --check **/*.ts",
"format:fix": "prettier --write **/*.ts"
Expand Down
16 changes: 7 additions & 9 deletions pkg/js/transformer/dsltojson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import OpenFGAParser, {
RelationDefPartialsContext,
RelationDefRewriteContext,
RelationDefTypeRestrictionContext,
RelationRecurseContext,
RelationRecurseNoDirectContext,
TypeDefContext,
TypeDefsContext,
} from "../gen/OpenFGAParser";
Expand Down Expand Up @@ -168,7 +166,7 @@ class OpenFgaDslListener extends OpenFGAListener {
const relationName = ctx.relationName().getText();
const rewrites = this.currentRelation?.rewrites;

let relationDef = parseExpression(rewrites, this.currentRelation?.operator);
const relationDef = parseExpression(rewrites, this.currentRelation?.operator);

if (relationDef) {
// Throw error if same named relation occurs more than once in a relationship definition block
Expand Down Expand Up @@ -250,17 +248,17 @@ class OpenFgaDslListener extends OpenFGAListener {
this.currentRelation?.rewrites?.push(partialRewrite);
};

exitRelationRecurse = (ctx: RelationRecurseContext) => {
exitRelationRecurse = () => {
const rewrites = this.currentRelation?.rewrites;

let relationDef = parseExpression(rewrites, this.currentRelation?.operator);
const relationDef = parseExpression(rewrites, this.currentRelation?.operator);

if (relationDef) {
this.currentRelation!.rewrites = [relationDef];
}
};

enterRelationRecurseNoDirect = (ctx: RelationRecurseNoDirectContext) => {
enterRelationRecurseNoDirect = () => {
this.rewriteStack?.push({
rewrites: this.currentRelation!.rewrites!,
operator: this.currentRelation!.operator!,
Expand All @@ -269,10 +267,10 @@ class OpenFgaDslListener extends OpenFGAListener {
this.currentRelation!.rewrites = [];
};

exitRelationRecurseNoDirect = (ctx: RelationRecurseNoDirectContext) => {
exitRelationRecurseNoDirect = () => {
const rewrites = this.currentRelation?.rewrites;

let relationDef = parseExpression(rewrites, this.currentRelation?.operator);
const relationDef = parseExpression(rewrites, this.currentRelation?.operator);

const popped = this.rewriteStack.pop();

Expand Down Expand Up @@ -351,7 +349,7 @@ class OpenFgaDslListener extends OpenFGAListener {
this.currentCondition!.expression = ctx.getText().trim();
};

exitCondition = (_ctx: ConditionContext) => {
exitCondition = () => {
if (this.currentCondition) {
this.authorizationModel.conditions![this.currentCondition.name!] = this.currentCondition!;

Expand Down
8 changes: 7 additions & 1 deletion pkg/js/transformer/jsontodsl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,13 @@ function parseDifference(
typeRestrictions: RelationReference[],
validator: DirectAssignmentValidator,
): string {
const base = parseSubRelation(typeName, relationName, relationDefinition!.difference!.base!, typeRestrictions, validator);
const base = parseSubRelation(
typeName,
relationName,
relationDefinition!.difference!.base!,
typeRestrictions,
validator,
);
const difference = parseSubRelation(
typeName,
relationName,
Expand Down
2 changes: 1 addition & 1 deletion pkg/js/util/exceptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ export const createSchemaVersionRequiredError = (props: BaseProps) => {
const { errors, lines, lineIndex, symbol } = props;
errors.push(
constructValidationError({
message: `schema version required`,
message: "schema version required",
lines,
lineIndex,
metadata: { symbol, errorType: ValidationError.SchemaVersionRequired },
Expand Down
9 changes: 4 additions & 5 deletions pkg/js/validator/validate-dsl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Keyword, ReservedKeywords } from "./keywords";
import { parseDSL } from "../transformer";
import { ConfigurationError, DSLSyntaxError, ModelValidationError, ModelValidationSingleError } from "../errors";
import { exceptionCollector } from "../util/exceptions";
import { string } from "yaml/dist/schema/common/string";

// eslint-disable-next-line no-useless-escape
export const defaultTypeRule = "^[^:#@\\s]{1,254}$";
Expand Down Expand Up @@ -38,7 +37,7 @@ interface RelationTargetParserResult {
rewrite: RewriteType;
}

const deepCopy = (object: any): any => {
const deepCopy = <T>(object: T): T => {
return JSON.parse(JSON.stringify(object));
};

Expand Down Expand Up @@ -225,7 +224,7 @@ function hasEntryPointOrLoop(
continue;
}

const [hasEntry, _] = hasEntryPointOrLoop(typeMap, decodedType, decodedRelation, assignableRelation, visited);
const [hasEntry] = hasEntryPointOrLoop(typeMap, decodedType, decodedRelation, assignableRelation, visited);
if (hasEntry) {
return [true, false];
}
Expand Down Expand Up @@ -276,7 +275,7 @@ function hasEntryPointOrLoop(
continue;
}

const [hasEntry, _] = hasEntryPointOrLoop(
const [hasEntry] = hasEntryPointOrLoop(
typeMap,
assignableType,
computedRelationName,
Expand Down Expand Up @@ -673,7 +672,7 @@ function modelValidation(
}

for (const conditionName in authorizationModel.conditions) {
const condition = authorizationModel.conditions[conditionName];
// const condition = authorizationModel.conditions[conditionName];
// Ensure that the nested condition name matches
// TODO: This does not make sense for the DSL, and is a JSON only error
// if (conditionName != condition.name) {
Expand Down

0 comments on commit 93175fd

Please sign in to comment.