question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Provide JSON schema for .lintstagedrc (that can be added to schemastore)

See original GitHub issue

Since .lintstagedrc is a JSON file, it can be validated if a schema is provided.

This schema could then be added to schemastore, which’d make it available on their public api for tools such as IntelliJ to download automatically.

I’m happy to attempt making such a schema if I get the time, but have created this issue for tracking, and in case someone who knows lint-staged better wants to take a crack (I’ve not actually used it yet, but love things that have schemas).


First whack at it, mostly accurate:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "lint-staged configuration.",
  "description": "Run linters against staged git files and don't let 💩 slip into your code base!",
  "type": "object",
  "additionalProperties": true,
  "definitions": {
    "linter": {
      "description": " keys (String) are glob patterns, values (Array<String> | String) are commands to execute.",
      "type": [ "string", "array" ],
      "items": {
        "type": "string"
      }
    }
  },
  "properties": {
    "$schema": {
      "type": "string"
    },
    "linters": {
      "description": " keys (String) are glob patterns, values (Array<String> | String) are commands to execute.",
      "type": "object",
      "additionalProperties": {
        "type": "string"
      }
    },
    "concurrent": {
      "description": "runs linters for each glob pattern simultaneously.",
      "type": "boolean",
      "default": true
    },
    "chunkSize ": {
      "description": "Max allowed chunk size based on number of files for glob pattern. This option is only applicable on Windows based systems to avoid command length limitations.",
      "type": "number"
    },
    "globOptions": {
      "description": "micromatch options to customize how glob patterns match files.",
      "type": "object",
      "properties": {
        "matchBase": {
          "type": "boolean",
          "default": true
        },
        "dot": {
          "type": "boolean",
          "default": true
        }
      },
      "additionalProperties": true
    },
    "ignore": {
      "description": "array of glob patterns to entirely ignore from any task.",
      "type": "array",
      "items": {
        "type": "string"
      },
      "default": "['**/docs/**/*.js']"
    },
    "subTaskConcurrency": {
      "description": "Controls concurrency for processing chunks generated for each linter. This option is only applicable on Windows. Execution is not concurrent by default.",
      "type": "number",
      "default": 1
    },
    "relative": {
      "description": "If true it will give the relative path from your package.json directory to your linter arguments.",
      "type": "boolean",
      "default": false
    }
  }
}

This only supports the advanced type configuration, as I need to look into how to switch additionalProperties based on if other properties are present 😃

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
G-Rathcommented, Aug 12, 2019

I added lint-staged schema to schemastore.

I’ll remove the advanced version in a few weeks, when I’ve cleared a few other things off my plate.

Q: would you be alright w/ supporting the $schema property? “support” in this case just means “ignore”.

usecase:

{
  "$schema": "http://json.schemastore.org/lintstagedrc.schema",
  "**/*.{t,j}s": "eslint",
  "**/.eslint{rc,ignore}": "npm run lint:all"
}

I have actually put it in the schema file for the “advanced” config, as so long as it didn’t do anything to valid that only specific properties were there, $schema shouldn’t cause problems, but it needs explicit support in the simple config since it’s pattern matching.

1reaction
G-Rathcommented, Jun 14, 2019

Finally done - took a lot of work, and most of my day, but it works:

{
  "$schema": "http://json-schema.org/draft-07/schema",
  "definitions": {
    "$schemaProperty": { "type": "string" },
    "linter": { "type": [ "string", "array" ] },
    "lintersMap": {
      "description": "keys (String) are glob patterns, values (Array<String> | String) are commands to execute.",
      "type": "object",
      "additionalProperties": {
        "$ref": "#/definitions/linter"
      }
    },
    "globOptions": {
      "description": "micromatch options to customize how glob patterns match files.",
      "type": "object",
      "properties": {
        "matchBase": {
          "type": "boolean",
          "default": true
        },
        "dot": {
          "type": "boolean",
          "default": true
        }
      },
      "additionalProperties": false
    },
    "advancedConfig": {
      "properties": {
        "$schema": { "$ref": "#/definitions/$schemaProperty" },
        "concurrent": {
          "description": "Controls if linters are run simultaneously for each glob pattern.",
          "type": "boolean",
          "default": true
        },
        "chunkSize": {
          "description": "Max allowed chunk size based on number of files for glob pattern. This option is only applicable on Windows based systems to avoid command length limitations",
          "type": "number",
          "minimum": 1
        },
        "globOptions": {
          "description": "micromatch options to customize how glob patterns match files.",
          "$ref": "#/definitions/globOptions"
        },
        "linters": {
          "description": "keys (String) are glob patterns, values (Array<String> | String) are commands to execute.",
          "$ref": "#/definitions/lintersMap"
        },
        "ignore": {
          "description": "array of glob patterns to entirely ignore from any task.",
          "type": "array",
          "items": {
            "type": "string"
          },
          "default": "['**/docs/**/*.js']"
        },
        "subTaskConcurrency": {
          "description": "Controls concurrency for processing chunks generated for each linter. This option is only applicable on Windows. Execution is not concurrent by default.",
          "type": "integer",
          "minimum": 1,
          "default": 1
        },
        "renderer": {
          "enum": [ "update", "verbose" ],
          "default": "update"
        },
        "relative": {
          "description": "If true it will give the relative path from your package.json directory to your linter arguments.",
          "type": "boolean",
          "default": false
        }
      },
      "additionalProperties": false
    },
    "basicConfig": {
      "properties": {
        "$schema": { "$ref": "#/definitions/$schemaProperty" }
      },
      "propertyNames": {
        "not": {
          "enum": [
            "concurrent",
            "chunkSize",
            "globOptions",
            "linters",
            "ignore",
            "subTaskConcurrency",
            "renderer",
            "relative"
          ]
        }
      },
      "additionalProperties": { "$ref": "#/definitions/linter" }
    }
  },
  "anyOf": [
    { "$ref": "#/definitions/advancedConfig" },
    { "$ref": "#/definitions/basicConfig" }
  ]
}

I’ll look to make a PR “soon”, along w/ automation, & ideally a test suite; all once I get the time.

Read more comments on GitHub >

github_iconTop Results From Across the Web

JSON Schema Store
JSON Schemas for common JSON file formats. ... Each schema file can be used in tooling such as command line validators, editor auto-completion...
Read more >
JSON schema for the win - Gleb Bahmutov
There are a lot of schemas for widely used JSON files on schemastore.org/json/ and you can add your own by making a pull...
Read more >
Frontend Handbook | Code Quality / Tools - Infinum
Lint-staged can be configured in many ways. We prefer configuration in .lintstagedrc file in JSON format. Lint-staged uses glob patterns which ...
Read more >
How to create your own auto-completion for JSON and YAML ...
The JSON Schema Store provides a very good set of schemas. Still, with so many different file types, of course, it can´t have...
Read more >
JSON Schema Store
JSON Schemas for common JSON file formats. ... In supported JSON editors like Visual Studio and Visual Studio Code, schema files can offer...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found