From a44c06152010144d6b550583e6e2024816b28c23 Mon Sep 17 00:00:00 2001 From: Ewan Harris Date: Wed, 14 Feb 2024 17:37:35 +0000 Subject: [PATCH 1/3] chore(js): fix eslint warnings --- pkg/js/index.ts | 6 +++--- pkg/js/package.json | 2 +- pkg/js/transformer/dsltojson.ts | 16 +++++++--------- pkg/js/transformer/jsontodsl.ts | 8 +++++++- pkg/js/util/exceptions.ts | 2 +- pkg/js/validator/validate-dsl.ts | 9 ++++----- 6 files changed, 23 insertions(+), 20 deletions(-) diff --git a/pkg/js/index.ts b/pkg/js/index.ts index f9484710..633c4400 100644 --- a/pkg/js/index.ts +++ b/pkg/js/index.ts @@ -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"; diff --git a/pkg/js/package.json b/pkg/js/package.json index 14d8f4c9..bc3122f6 100644 --- a/pkg/js/package.json +++ b/pkg/js/package.json @@ -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" diff --git a/pkg/js/transformer/dsltojson.ts b/pkg/js/transformer/dsltojson.ts index f248f7d2..8c00d295 100644 --- a/pkg/js/transformer/dsltojson.ts +++ b/pkg/js/transformer/dsltojson.ts @@ -22,8 +22,6 @@ import OpenFGAParser, { RelationDefPartialsContext, RelationDefRewriteContext, RelationDefTypeRestrictionContext, - RelationRecurseContext, - RelationRecurseNoDirectContext, TypeDefContext, TypeDefsContext, } from "../gen/OpenFGAParser"; @@ -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 @@ -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!, @@ -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(); @@ -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!; diff --git a/pkg/js/transformer/jsontodsl.ts b/pkg/js/transformer/jsontodsl.ts index aaea5ea5..b0df9420 100644 --- a/pkg/js/transformer/jsontodsl.ts +++ b/pkg/js/transformer/jsontodsl.ts @@ -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, diff --git a/pkg/js/util/exceptions.ts b/pkg/js/util/exceptions.ts index 3b571e42..b903ccdc 100644 --- a/pkg/js/util/exceptions.ts +++ b/pkg/js/util/exceptions.ts @@ -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 }, diff --git a/pkg/js/validator/validate-dsl.ts b/pkg/js/validator/validate-dsl.ts index 45ef9cb4..eb2e8a9e 100644 --- a/pkg/js/validator/validate-dsl.ts +++ b/pkg/js/validator/validate-dsl.ts @@ -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}$"; @@ -38,7 +37,7 @@ interface RelationTargetParserResult { rewrite: RewriteType; } -const deepCopy = (object: any): any => { +const deepCopy = (object: T): T => { return JSON.parse(JSON.stringify(object)); }; @@ -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]; } @@ -276,7 +275,7 @@ function hasEntryPointOrLoop( continue; } - const [hasEntry, _] = hasEntryPointOrLoop( + const [hasEntry, ] = hasEntryPointOrLoop( typeMap, assignableType, computedRelationName, @@ -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) { From f23ec61894f1677cae0eeaf2155321ce376d0431 Mon Sep 17 00:00:00 2001 From: Ewan Harris Date: Wed, 14 Feb 2024 17:38:50 +0000 Subject: [PATCH 2/3] chore(js): fix prettier errors --- pkg/js/transformer/jsontodsl.ts | 2 +- pkg/js/validator/validate-dsl.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/js/transformer/jsontodsl.ts b/pkg/js/transformer/jsontodsl.ts index b0df9420..213b104c 100644 --- a/pkg/js/transformer/jsontodsl.ts +++ b/pkg/js/transformer/jsontodsl.ts @@ -100,7 +100,7 @@ function parseDifference( relationName, relationDefinition!.difference!.base!, typeRestrictions, - validator + validator, ); const difference = parseSubRelation( typeName, diff --git a/pkg/js/validator/validate-dsl.ts b/pkg/js/validator/validate-dsl.ts index eb2e8a9e..1aaa8cae 100644 --- a/pkg/js/validator/validate-dsl.ts +++ b/pkg/js/validator/validate-dsl.ts @@ -224,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]; } @@ -275,7 +275,7 @@ function hasEntryPointOrLoop( continue; } - const [hasEntry, ] = hasEntryPointOrLoop( + const [hasEntry] = hasEntryPointOrLoop( typeMap, assignableType, computedRelationName, From ad951c45e2d451b5b2fdf8a240254307fea9dde6 Mon Sep 17 00:00:00 2001 From: Ewan Harris Date: Wed, 14 Feb 2024 17:39:05 +0000 Subject: [PATCH 3/3] chore: adjust make commands and change usage in ci make lint now runs prettier and eslint together, allowing both to error independently, make format will now fix any autofixable issues in eslint and run prettier, eslint can fail and prettier will still run. In CI we now also run the lint as we want CI to fail if there's issues, not fix them silently but not inform us --- .github/workflows/main-js.yaml | 5 +---- pkg/js/Makefile | 4 ++-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/.github/workflows/main-js.yaml b/.github/workflows/main-js.yaml index ebc90a37..a920f6c7 100644 --- a/.github/workflows/main-js.yaml +++ b/.github/workflows/main-js.yaml @@ -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: diff --git a/pkg/js/Makefile b/pkg/js/Makefile index 3491fa34..af83c05f 100644 --- a/pkg/js/Makefile +++ b/pkg/js/Makefile @@ -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 \ No newline at end of file