Stuk / eslint-plugin-header

ESLint plugin to ensure that files begin with given comment
MIT License
71 stars 36 forks source link

Error: Key "rules": Key "header/header": should NOT have more than 0 items. #57

Closed firefoxNX closed 5 days ago

firefoxNX commented 3 months ago

using eslint version 9.4.0 with eslint-plugin-header gives this error -

Error: Key "rules": Key "header/header":
    Value ["block",{"pattern":"Copyright \\d{4}, CompanyName, Inc.  All rights reserved.","template":"Copyright 2024, CompanyName, Inc.  All rights reserved."}] should NOT have more than 0 items.

    at RuleValidator.validate (/Users/vineet/Documents/learn_eslint/node_modules/eslint/lib/config/rule-validator.js:170:27)
    at [finalizeConfig] (/Users/vineet/Documents/learn_eslint/node_modules/eslint/lib/config/flat-config-array.js:317:23)
    at FlatConfigArray.getConfigWithStatus (/Users/vineet/Documents/learn_eslint/node_modules/@eslint/config-array/dist/cjs/index.cjs:1145:55)
    at FlatConfigArray.getConfig (/Users/vineet/Documents/learn_eslint/node_modules/@eslint/config-array/dist/cjs/index.cjs:1163:15)
    at ESLint.calculateConfigForFile (/Users/vineet/Documents/learn_eslint/node_modules/eslint/lib/eslint/eslint.js:1169:24)
    at async ESLint.isPathIgnored (/Users/vineet/Documents/learn_eslint/node_modules/eslint/lib/eslint/eslint.js:1191:24)

see https://github.com/firefoxNX/learn_eslint to reproduce the issue.

tonyganchev commented 3 months ago

Also reproducing this issue.

tonyganchev commented 3 months ago

Seems that ESLint now mandates that meta.schema field is mandatory for rules with options: https://eslint.org/docs/latest/extend/custom-rules. I went ahead and set schema: false before https://github.com/Stuk/eslint-plugin-header/blob/63f18ce725edb23a2d274b234df7f12ff0b7f009/lib/rules/header.js#L125 and linting passed. I can probably prepare a better fix that actually validates the schema.

tonyganchev commented 3 months ago

https://github.com/Stuk/eslint-plugin-header/pull/58 - I have a PR to disable schema validation

firefoxNX commented 3 months ago

Thanks @tonyganchev. I verified and its working after disabling schema validation.

@Stuk - can you please review the fix?

tonyganchev commented 2 months ago

I've published a fork at https://www.npmjs.com/package/@tony.ganchev/eslint-plugin-header containing my fix.

gavinbarron commented 2 months ago

I just spent a little time this afternoon looking at this. Building it using JSONSchema Draft 2020-12 looks something like this:

{
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "$id": "https://json-schema.org/draft/2020-12/schema-enum",
    "type": "array",
    "minItems": 1,
    "maxItems": 3,
    "prefixItems": [
      { 
        "oneOf": [{
            "type": "string",
            "enum": ["block", "inline"]
        },{
          "type": "string",
          "pattern": "[.*]*.*.js"
        }]
      },
      {
        "oneOf": [{
            "type": "string",
        },{
          "type": "array",
          "prefixItems": [
            {
              "oneOf": [
                {
                  "type": "object",
                  "properties": {
                    "pattern": {
                      "type": "string"
                    },
                    "template": {
                        "type": "string"
                    }
                  },
                  "required": ["pattern"]
                },
                {"type": "string"}
              ]
            },
            {"type": "string"}
          ]
        }]
      },
      {
        "type": "number",
          "minimum": 0
      }
    ]
}
Laffery commented 1 week ago

I add the following code in the eslint.config.js as workaround

const pluginHeader = require('eslint-plugin-header');

+ pluginHeader.rules.header.meta.schema = false;
firefoxNX commented 5 days ago

Closing because @Laffery's workaround works!