Skip to content

roscrl/order

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

order

Keep YAML and JSON files organised by checking their property order against a JSON schema.

Use order if:

  • You have many contributors to a repository and want to enforce style consistency
  • You want to reduce mental effort in code reviews with a predictable pattern.
  • You want your YAML or JSON files to stay neat and consistent.

Installation

go get github.com/roscrl/order

Usage

package main

import (
    "fmt"
    "github.com/roscrl/order"
)

func main() {
    // Check if YAML file conforms to property order defined in JSON schema
    err := order.Lint("config.yaml", "schema.json")
    if err != nil {
        return fmt.Errorf("linting properties order against json schema: %v", err)
    }
}

How It Works

order looks at the properties list in your JSON schema and makes sure your YAML or JSON file follows the same order.

Properties need to match the schema's order (e.g., "name" before "version").

Examples

JSON Schema Example

{
  "properties": {
    "name": { "type": "string" },
    "version": { "type": "string" },
    "description": { "type": "string" },
    "dependencies": {
      "properties": {
        "production": { "type": "object" },
        "development": { "type": "object" }
      }
    },
    "scripts": { "type": "object" }
  }
}

Good YAML

name: my-package
version: 1.0.0
description: A sample package
dependencies:
  production:
    some-lib: ^1.0.0
  development:
    test-lib: ^2.0.0
scripts:
  test: jest

Bad YAML (Wrong Order)

version: 1.0.0  # Should come after 'name'
name: my-package
description: A sample package
dependencies:
  development:  # Should come after 'production'
    test-lib: ^2.0.0
  production:
    some-lib: ^1.0.0
scripts:
  test: jest

This causes an error: "version" is out of order; it should come after "name".

See examples/main.go for a complete example.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages