loop-payments / prisma-lint

A linter for Prisma schema files.
https://www.npmjs.com/package/prisma-lint
MIT License
120 stars 4 forks source link

Support for prisma `enum`? #345

Closed canadaduane closed 3 months ago

canadaduane commented 3 months ago

We have several enum declarations in our schema.prisma file, e.g.:

enum GradeLevel {
  KINDERGARTEN   @map("kindergarten")
  FIRST          @map("first")
  SECOND         @map("second")
  THIRD          @map("third")
  FOURTH         @map("fourth")
  FIFTH          @map("fifth")
  SIXTH          @map("sixth")
  SEVENTH        @map("seventh")
  EIGHTH         @map("eighth")
  NINTH          @map("ninth")
  TENTH          @map("tenth")
  ELEVENTH       @map("eleventh")
  TWELFTH        @map("twelfth")
  THIRTEEN       @map("thirteen")
  POST_SECONDARY @map("post_secondary")
  OTHER          @map("other")
}

However, when running prisma-lint I see the following syntax error:

MismatchedTokenException: Expecting --> '}' <-- but found --> '@' <--
    at RecognizerEngine.consumeInternalError (/Users/duane/schoolai/Coteacher/node_modules/.pnpm/chevrotain@10.5.0/node_modules/chevrotain/lib/src/parse/parser/traits/recognizer_engine.js:500:31)
    at RecognizerEngine.consumeInternal (/Users/duane/schoolai/Coteacher/node_modules/.pnpm/chevrotain@10.5.0/node_modules/chevrotain/lib/src/parse/parser/traits/recognizer_engine.js:475:22)
    at RecognizerApi.CONSUME (/Users/duane/schoolai/Coteacher/node_modules/.pnpm/chevrotain@10.5.0/node_modules/chevrotain/lib/src/parse/parser/traits/recognizer_api.js:47:21)
    at PrismaParser.<anonymous> (/Users/duane/schoolai/Coteacher/node_modules/.pnpm/@mrleebo+prisma-ast@0.11.0/node_modules/@mrleebo/prisma-ast/dist/prisma-ast.cjs.development.js:475:13)
    at PrismaParser.invokeRuleWithTry [as block] (/Users/duane/schoolai/Coteacher/node_modules/.pnpm/chevrotain@10.5.0/node_modules/chevrotain/lib/src/parse/parser/traits/recognizer_engine.js:133:26)
    at RecognizerEngine.subruleInternal (/Users/duane/schoolai/Coteacher/node_modules/.pnpm/chevrotain@10.5.0/node_modules/chevrotain/lib/src/parse/parser/traits/recognizer_engine.js:447:37)
    at RecognizerApi.SUBRULE (/Users/duane/schoolai/Coteacher/node_modules/.pnpm/chevrotain@10.5.0/node_modules/chevrotain/lib/src/parse/parser/traits/recognizer_api.js:77:21)
    at PrismaParser.<anonymous> (/Users/duane/schoolai/Coteacher/node_modules/.pnpm/@mrleebo+prisma-ast@0.11.0/node_modules/@mrleebo/prisma-ast/dist/prisma-ast.cjs.development.js:620:13)
    at PrismaParser.invokeRuleWithTry [as component] (/Users/duane/schoolai/Coteacher/node_modules/.pnpm/chevrotain@10.5.0/node_modules/chevrotain/lib/src/parse/parser/traits/recognizer_engine.js:133:26)
    at RecognizerEngine.subruleInternal (/Users/duane/schoolai/Coteacher/node_modules/.pnpm/chevrotain@10.5.0/node_modules/chevrotain/lib/src/parse/parser/traits/recognizer_engine.js:447:37) {
  token: {
    image: '@',
    startOffset: 35,
    endOffset: 35,
    startLine: 2,
    endLine: 2,
    startColumn: 18,
    endColumn: 18,
    tokenTypeIdx: 18,
    tokenType: {
      name: 'FieldAttribute',
      PATTERN: /@/,
      CATEGORIES: [Array],
      tokenTypeIdx: 18,
      categoryMatches: [],
      categoryMatchesMap: {},
      isParent: false,
      LABEL: "'@'"
    }
  },
  resyncedTokens: [],
  previousToken: {
    image: 'KINDERGARTEN',
    startOffset: 20,
    endOffset: 31,
    startLine: 2,
    endLine: 2,
    startColumn: 3,
    endColumn: 14,
    tokenTypeIdx: 3,
    tokenType: {
      name: 'Identifier',
      PATTERN: /[a-zA-Z][\w-]*/,
      tokenTypeIdx: 3,
      CATEGORIES: [],
      categoryMatches: [],
      categoryMatchesMap: {},
      isParent: false
    }
  },
  context: {
    ruleStack: [ 'schema', 'component', 'block' ],
    ruleOccurrenceStack: [ 0, 0, 0 ]
  }
}

Is the @map syntax not supported in enum, perhaps?

canadaduane commented 3 months ago

I've added a request to support this new-ish syntax here: https://github.com/MrLeebo/prisma-ast/issues/41

maxh commented 3 months ago

Perfect, once that library supports it we can upgrade.

canadaduane commented 3 months ago

They were remarkably quick in implementing! Can we bump the dependency version?

canadaduane commented 3 months ago

Thank you!