diff --git a/.github/dependabot.yml b/.github/dependabot.yml index c08016e..4a6fcca 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -5,3 +5,9 @@ updates: schedule: interval: "daily" labels: ["dependencies"] + - package-ecosystem: "npm" + versioning-strategy: lockfile-only + directory: "/" + schedule: + interval: "daily" + labels: ["dependencies"] diff --git a/.nvmrc b/.nvmrc index 23d9c36..4a1f488 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -16.13.2 +18.17.1 diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 26c4a64..f8992a1 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -1,3 +1,3 @@ { - "recommendations": ["esbenp.prettier-vscode", "redhat.vscode-yaml"] + "recommendations": ["esbenp.prettier-vscode", "redhat.vscode-yaml", "go.golang"] } diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 1d130ac..83cc161 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -4,7 +4,7 @@ We are an open source project on GitHub and would enjoy your contributions! Plea ### Requirements -- Node >= 16.13.2 +- Node >= 18.x - npm >= 8.x - Go >= 1.17 @@ -27,7 +27,7 @@ npm install The following workflow is recommended to work on any of the HashiCorp TextMate grammars in this repo: 1. Add or modify grammar in the `src/_main.yml` or product specific YAML file in like `src/terraform.yml`. -1. Change directory to `builder` and run `go run main.go build` +1. Run `npm run build` 1. Add a new test case file or modify existing test case files inside the `tests/snapshot/` directory. Make sure to put the new file in the correct folder or it will not be tested. 1. Run `npm run test:snap:` until the tests pass. diff --git a/builder/main.go b/builder/main.go deleted file mode 100644 index 3c3020e..0000000 --- a/builder/main.go +++ /dev/null @@ -1,206 +0,0 @@ -// Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: MPL-2.0 - -package main - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "os" - "path/filepath" - "strings" - - "github.com/hashicorp/go-multierror" - "github.com/mitchellh/cli" - "github.com/spf13/viper" -) - -func main() { - c := &cli.CLI{ - Name: "builder", - Version: "", - Args: os.Args[1:], - HelpWriter: os.Stdout, - } - - ui := &cli.ColoredUi{ - ErrorColor: cli.UiColorRed, - WarnColor: cli.UiColorYellow, - Ui: &cli.BasicUi{ - Writer: os.Stdout, - Reader: os.Stdin, - ErrorWriter: os.Stderr, - }, - } - - c.Commands = map[string]cli.CommandFactory{ - "build": func() (cli.Command, error) { - return &BuildCommand{ - Ui: ui, - }, nil - }, - } - - exitStatus, err := c.Run() - if err != nil { - ui.Error("Error: " + err.Error()) - } - - os.Exit(exitStatus) -} - -type BuildCommand struct { - Ui cli.Ui -} - -func (c *BuildCommand) Help() string { - helpText := `Usage: syntax build - -` + c.Synopsis() - return strings.TrimSpace(helpText) -} - -func (c *BuildCommand) Synopsis() string { - return "Builds syntax files" -} - -func (c *BuildCommand) Run(args []string) int { - // This currently uses the cwd to find all the files used here - // This can be improved in the future to accept User input or use some kind of - // convention for where things are located - wd, err := os.Getwd() - if err != nil { - return 1 - } - - // The _main.yml file is where all rules in the Patterns and the Repository are defined - // Each product file provides specific overrides for rules defined in _main.yml - // Here we build a main Viper instance to store the config we will merge in product specific maps to - mainFile := filepath.Join(wd, "../src/_main.yml") - c.Ui.Info(fmt.Sprintf("Pulling in main template: %s", mainFile)) - mainViper := viper.New() - mainViper.SetConfigFile(mainFile) - if err := mainViper.ReadInConfig(); err == nil { - c.Ui.Info(fmt.Sprintf("Merging config file: %v", mainViper.ConfigFileUsed())) - } else { - c.Ui.Error(fmt.Sprintf("Error reading %v: %v", mainViper.ConfigFileUsed(), err)) - return 1 - } - - var result *multierror.Error - // For each product defined, read the yml and merge into the main Viper instance - products := []string{"hcl", "terraform"} - for _, product := range products { - c.Ui.Info(fmt.Sprintf("Evaluating %s", product)) - productFile := filepath.Join(wd, fmt.Sprintf("../src/%s.yml", product)) - c.Ui.Info(fmt.Sprintf("Processing: %s", productFile)) - - // Create a product Viper instance that reads each product yml for rules - productV := viper.New() - productV.SetConfigFile(productFile) - if err := productV.ReadInConfig(); err == nil { - c.Ui.Info(fmt.Sprintf("Merging config file: %v", productV.ConfigFileUsed())) - } else { - c.Ui.Error(fmt.Sprintf("Error reading %v: %v", productV.ConfigFileUsed(), err.Error())) - result = multierror.Append(result, err) - continue - } - - // merge the product Viper map into the main Viper instance - // This overrides anything already loaded so each product can replace existing - // rules and/or provide new ones - if err := mainViper.MergeConfigMap(productV.AllSettings()); err != nil { - c.Ui.Error(fmt.Sprintf("Unable to merge values from %v: %v", productV.ConfigFileUsed(), err.Error())) - result = multierror.Append(result, err) - continue - } - - // Export the merged map to a struct so we can write to file - c.Ui.Info(fmt.Sprintf("Building %s", product)) - var config TextMateGrammar - err := mainViper.Unmarshal(&config) - if err != nil { - c.Ui.Error(fmt.Sprintf("Unable to merge values from %s: %s", productV.ConfigFileUsed(), err.Error())) - result = multierror.Append(result, err) - continue - } - - // Write the struct to JSON. We can modify this to include writing to other formats in the future - productGrammarFile := filepath.Join(wd, fmt.Sprintf("../syntaxes/%s.tmGrammar.json", product)) - c.Ui.Info(fmt.Sprintf("Writing %s", productGrammarFile)) - err = writeJSON(config, productGrammarFile) - if err != nil { - c.Ui.Error(fmt.Sprintf("Error writing grammar file: %v", err)) - result = multierror.Append(result, err) - } - } - if result.ErrorOrNil() != nil { - return 1 - } else { - return 0 - } -} - -func writeJSON(data TextMateGrammar, file string) error { - // We don't use json.MarshalIndent here because that escapes special characters automatically - // without allowing you to change the behavior. So, we make our own encoder and disable - // encoding and indent on our own. - buffer := &bytes.Buffer{} - encoder := json.NewEncoder(buffer) - encoder.SetEscapeHTML(false) - err := encoder.Encode(data) - if err != nil { - return err - } - - var out bytes.Buffer - err = json.Indent(&out, buffer.Bytes(), "", " ") - if err != nil { - return err - } - - err = ioutil.WriteFile(file, out.Bytes(), 0644) - if err != nil { - return err - } - - return nil -} - -// As defined in https://macromates.com/manual/en/language_grammars -type TextMateGrammar struct { - ScopeName string `json:"scopeName"` - Name string `json:"name"` - UUID string `json:"uuid"` - FileTypes []string `json:"fileTypes"` - Patterns []Rule `json:"patterns"` - Repository map[string]Rule `json:"repository"` -} - -type Rule struct { - Include string `json:"include,omitempty"` - Name string `json:"name,omitempty"` - Match string `json:"match,omitempty"` - Begin string `json:"begin,omitempty"` - End string `json:"end,omitempty"` - ContentName string `json:"contentName,omitempty"` - Comment string `json:"comment,omitempty"` - Captures map[string]Capture `json:"captures,omitempty"` - BeginCaptures map[string]Capture `json:"beginCaptures,omitempty"` - EndCaptures map[string]Capture `json:"endCaptures,omitempty"` - Patterns []Rule `json:"patterns,omitempty"` -} - -type Capture struct { - Name string `json:"name,omitempty"` - Patterns []CapturePattern `json:"patterns,omitempty"` -} - -type CapturePattern struct { - Match string `json:"match,omitempty"` - Comment string `json:"comment,omitempty"` - Name string `json:"name,omitempty"` - Include string `json:"include,omitempty"` -} diff --git a/cmd/builder/build.go b/cmd/builder/build.go new file mode 100644 index 0000000..a928e19 --- /dev/null +++ b/cmd/builder/build.go @@ -0,0 +1,112 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package main + +import ( + "fmt" + "os" + "path/filepath" + "strings" + + "github.com/hashicorp/go-multierror" + "github.com/mitchellh/cli" + "github.com/spf13/viper" +) +type BuildCommand struct { + Ui cli.Ui +} + +func (c *BuildCommand) Help() string { + helpText := `Usage: syntax build + +` + c.Synopsis() + return strings.TrimSpace(helpText) +} + +func (c *BuildCommand) Synopsis() string { + return "Builds syntax files" +} + +func (c *BuildCommand) Run(args []string) int { + // This currently uses the cwd to find all the files used here + // This can be improved in the future to accept User input or use some kind of + // convention for where things are located + wd, err := os.Getwd() + if err != nil { + return 1 + } + + syntaxSourcePath := filepath.Join(wd, "src") + syntaxDeployPath := filepath.Join(wd, "syntaxes") + + // The _main.yml file is where all rules in the Patterns and the Repository are defined + // Each product file provides specific overrides for rules defined in _main.yml + mainFile := filepath.Join(syntaxSourcePath, "_main.yml") + + var result *multierror.Error + // For each product defined, read the yml and merge into the main Viper instance + products := []string{"hcl", "terraform"} + for _, product := range products { + c.Ui.Info(fmt.Sprintf("Evaluating %s", product)) + + // Here we build a main Viper instance to store the config we will merge in product specific maps. + // Note that the main viper configuration needs to be re-read for each product and errors here + // are terminal + mainViper, err := c.newViper(mainFile) + if err != nil { + c.Ui.Error(fmt.Sprintf("Error reading %v: %v", mainViper.ConfigFileUsed(), err.Error())) + return 1 + } + + productFile := filepath.Join(syntaxSourcePath, fmt.Sprintf("%s.yml", product)) + c.Ui.Info(fmt.Sprintf("Processing: %s", productFile)) + + // Create a product Viper instance that reads each product yml for rules + productV, err := c.newViper(productFile) + if err != nil { + c.Ui.Error(fmt.Sprintf("Error reading %v: %v", productV.ConfigFileUsed(), err.Error())) + result = multierror.Append(result, err) + continue + } + + c.Ui.Info(fmt.Sprintf("Merging config file: %v", productV.ConfigFileUsed())) + if err := mainViper.MergeConfigMap(productV.AllSettings()); err != nil { + c.Ui.Error(fmt.Sprintf("Unable to merge values from %v: %v", productV.ConfigFileUsed(), err.Error())) + result = multierror.Append(result, err) + continue + } + + // Export the merged map to a struct so we can write to file + c.Ui.Info(fmt.Sprintf("Building %s", product)) + var config TextMateGrammar + err = mainViper.Unmarshal(&config) + if err != nil { + c.Ui.Error(fmt.Sprintf("Unable to merge values from %s: %s", productV.ConfigFileUsed(), err.Error())) + result = multierror.Append(result, err) + continue + } + + // Write the struct to JSON. We can modify this to include writing to other formats in the future + productGrammarFile := filepath.Join(syntaxDeployPath, fmt.Sprintf("%s.tmGrammar.json", product)) + c.Ui.Info(fmt.Sprintf("Writing %s", productGrammarFile)) + err = writeJSON(config, productGrammarFile) + if err != nil { + c.Ui.Error(fmt.Sprintf("Error writing grammar file: %v", err)) + result = multierror.Append(result, err) + } + } + + if result.ErrorOrNil() != nil { + return 1 + } else { + return 0 + } +} + +func (c *BuildCommand) newViper(filepath string) (*viper.Viper, error) { + v := viper.New() + v.SetConfigFile(filepath) + err := v.ReadInConfig() + return v, err +} diff --git a/cmd/builder/main.go b/cmd/builder/main.go new file mode 100644 index 0000000..3fbff31 --- /dev/null +++ b/cmd/builder/main.go @@ -0,0 +1,44 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package main + +import ( + "os" + + "github.com/mitchellh/cli" +) + +func main() { + c := &cli.CLI{ + Name: "builder", + Version: "", + Args: os.Args[1:], + HelpWriter: os.Stdout, + } + + ui := &cli.ColoredUi{ + ErrorColor: cli.UiColorRed, + WarnColor: cli.UiColorYellow, + Ui: &cli.BasicUi{ + Writer: os.Stdout, + Reader: os.Stdin, + ErrorWriter: os.Stderr, + }, + } + + c.Commands = map[string]cli.CommandFactory{ + "build": func() (cli.Command, error) { + return &BuildCommand{ + Ui: ui, + }, nil + }, + } + + exitStatus, err := c.Run() + if err != nil { + ui.Error("Error: " + err.Error()) + } + + os.Exit(exitStatus) +} diff --git a/cmd/builder/textmate.go b/cmd/builder/textmate.go new file mode 100644 index 0000000..3feea7b --- /dev/null +++ b/cmd/builder/textmate.go @@ -0,0 +1,72 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package main + +import ( + "bytes" + "encoding/json" + "os" +) + +// As defined in https://macromates.com/manual/en/language_grammars +type TextMateGrammar struct { + ScopeName string `json:"scopeName"` + Name string `json:"name"` + UUID string `json:"uuid"` + FileTypes []string `json:"fileTypes"` + Patterns []Rule `json:"patterns"` + Repository map[string]Rule `json:"repository"` +} + +type Rule struct { + Include string `json:"include,omitempty"` + Name string `json:"name,omitempty"` + Match string `json:"match,omitempty"` + Begin string `json:"begin,omitempty"` + End string `json:"end,omitempty"` + ContentName string `json:"contentName,omitempty"` + Comment string `json:"comment,omitempty"` + Captures map[string]Capture `json:"captures,omitempty"` + BeginCaptures map[string]Capture `json:"beginCaptures,omitempty"` + EndCaptures map[string]Capture `json:"endCaptures,omitempty"` + Patterns []Rule `json:"patterns,omitempty"` +} + +type Capture struct { + Name string `json:"name,omitempty"` + Patterns []CapturePattern `json:"patterns,omitempty"` +} + +type CapturePattern struct { + Match string `json:"match,omitempty"` + Comment string `json:"comment,omitempty"` + Name string `json:"name,omitempty"` + Include string `json:"include,omitempty"` +} + +func writeJSON(data TextMateGrammar, file string) error { + // We don't use json.MarshalIndent here because that escapes special characters automatically + // without allowing you to change the behavior. So, we make our own encoder and disable + // encoding and indent on our own. + buffer := &bytes.Buffer{} + encoder := json.NewEncoder(buffer) + encoder.SetEscapeHTML(false) + err := encoder.Encode(data) + if err != nil { + return err + } + + var out bytes.Buffer + err = json.Indent(&out, buffer.Bytes(), "", " ") + if err != nil { + return err + } + + err = os.WriteFile(file, out.Bytes(), 0644) + if err != nil { + return err + } + + return nil +} diff --git a/builder/go.mod b/go.mod similarity index 100% rename from builder/go.mod rename to go.mod diff --git a/builder/go.sum b/go.sum similarity index 100% rename from builder/go.sum rename to go.sum diff --git a/package-lock.json b/package-lock.json index 7e0b4a0..b683818 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,7 +1,7 @@ { "name": "syntax", "version": "0.4.1", - "lockfileVersion": 2, + "lockfileVersion": 3, "requires": true, "packages": { "": { @@ -67,13 +67,13 @@ "node_modules/color-name": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", - "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", + "integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==", "dev": true }, "node_modules/commander": { - "version": "9.2.0", - "resolved": "https://registry.npmjs.org/commander/-/commander-9.2.0.tgz", - "integrity": "sha512-e2i4wANQiSXgnrBlIatyHtP1odfUp0BbV5Y5nEGbxtIrStkEOAAzCUirvLBNXHLr7kwLvJl6V+4V3XV9x7Wd9w==", + "version": "9.5.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-9.5.0.tgz", + "integrity": "sha512-KRs7WVDKg86PWiuAqhDrAQnTXZKraVcCc6vFdL14qrZ/DcWwuRo7VoiYXalXO7S5GKpqYiVEwCbgFDfxNHKJBQ==", "dev": true, "engines": { "node": "^12.20.0 || >=14" @@ -82,7 +82,7 @@ "node_modules/concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", + "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==", "dev": true }, "node_modules/diff": { @@ -97,7 +97,7 @@ "node_modules/escape-string-regexp": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", - "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", + "integrity": "sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==", "dev": true, "engines": { "node": ">=0.8.0" @@ -106,19 +106,19 @@ "node_modules/fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", - "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", + "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==", "dev": true }, "node_modules/glob": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.0.tgz", - "integrity": "sha512-lmLf6gtyrPq8tTjSmrO94wBeQbFR3HbLHbuyD69wuyQkImp2hWqMGB47OX65FBkPffO641IP9jWa1z4ivqG26Q==", + "version": "7.2.3", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", + "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", "dev": true, "dependencies": { "fs.realpath": "^1.0.0", "inflight": "^1.0.4", "inherits": "2", - "minimatch": "^3.0.4", + "minimatch": "^3.1.1", "once": "^1.3.0", "path-is-absolute": "^1.0.0" }, @@ -132,7 +132,7 @@ "node_modules/has-flag": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", - "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=", + "integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==", "dev": true, "engines": { "node": ">=4" @@ -141,7 +141,7 @@ "node_modules/inflight": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", - "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", + "integrity": "sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==", "dev": true, "dependencies": { "once": "^1.3.0", @@ -169,7 +169,7 @@ "node_modules/once": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", - "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", + "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", "dev": true, "dependencies": { "wrappy": "1" @@ -178,22 +178,25 @@ "node_modules/path-is-absolute": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", - "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", + "integrity": "sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==", "dev": true, "engines": { "node": ">=0.10.0" } }, "node_modules/prettier": { - "version": "2.5.1", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.5.1.tgz", - "integrity": "sha512-vBZcPRUR5MZJwoyi3ZoyQlc1rXeEck8KgeC9AwwOn+exuxLxq5toTRDTSaVrXHxelDMHy9zlicw8u66yxoSUFg==", + "version": "2.8.8", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.8.tgz", + "integrity": "sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==", "dev": true, "bin": { "prettier": "bin-prettier.js" }, "engines": { "node": ">=10.13.0" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" } }, "node_modules/supports-color": { @@ -209,21 +212,21 @@ } }, "node_modules/vscode-oniguruma": { - "version": "1.6.1", - "resolved": "https://registry.npmjs.org/vscode-oniguruma/-/vscode-oniguruma-1.6.1.tgz", - "integrity": "sha512-vc4WhSIaVpgJ0jJIejjYxPvURJavX6QG41vu0mGhqywMkQqulezEqEQ3cO3gc8GvcOpX6ycmKGqRoROEMBNXTQ==", + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/vscode-oniguruma/-/vscode-oniguruma-1.7.0.tgz", + "integrity": "sha512-L9WMGRfrjOhgHSdOYgCt/yRMsXzLDJSL7BPrOZt73gU0iWO4mpqzqQzOz5srxqTvMBaR0XZTSrVWo4j55Rc6cA==", "dev": true }, "node_modules/vscode-textmate": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/vscode-textmate/-/vscode-textmate-7.0.1.tgz", - "integrity": "sha512-zQ5U/nuXAAMsh691FtV0wPz89nSkHbs+IQV8FDk+wew9BlSDhf4UmWGlWJfTR2Ti6xZv87Tj5fENzKf6Qk7aLw==", + "version": "7.0.4", + "resolved": "https://registry.npmjs.org/vscode-textmate/-/vscode-textmate-7.0.4.tgz", + "integrity": "sha512-9hJp0xL7HW1Q5OgGe03NACo7yiCTMEk3WU/rtKXUbncLtdg6rVVNJnHwD88UhbIYU2KoxY0Dih0x+kIsmUKn2A==", "dev": true }, "node_modules/vscode-tmgrammar-test": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/vscode-tmgrammar-test/-/vscode-tmgrammar-test-0.1.1.tgz", - "integrity": "sha512-0WvD3U+E0KV95bNT7v5g7PQ85JfAjh9MuXOy1dgwZskkCsA8ASiSy60iv30JOZrM6dBjJZooGUAybRAIB+Song==", + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/vscode-tmgrammar-test/-/vscode-tmgrammar-test-0.1.2.tgz", + "integrity": "sha512-tLJZMAP/NWeRwlpHzjSXx+HvjJzFltndoyR6AK9fJRGjALJX6Pg7EOiYyznpJ4TNC2eMmF3IRbcZBWzJwN+n5g==", "dev": true, "dependencies": { "chalk": "^2.4.2", @@ -241,197 +244,7 @@ "node_modules/wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", - "dev": true - } - }, - "dependencies": { - "ansi-styles": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", - "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", - "dev": true, - "requires": { - "color-convert": "^1.9.0" - } - }, - "balanced-match": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", - "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", - "dev": true - }, - "brace-expansion": { - "version": "1.1.11", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", - "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", - "dev": true, - "requires": { - "balanced-match": "^1.0.0", - "concat-map": "0.0.1" - } - }, - "chalk": { - "version": "2.4.2", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", - "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", - "dev": true, - "requires": { - "ansi-styles": "^3.2.1", - "escape-string-regexp": "^1.0.5", - "supports-color": "^5.3.0" - } - }, - "color-convert": { - "version": "1.9.3", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", - "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", - "dev": true, - "requires": { - "color-name": "1.1.3" - } - }, - "color-name": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", - "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", - "dev": true - }, - "commander": { - "version": "9.2.0", - "resolved": "https://registry.npmjs.org/commander/-/commander-9.2.0.tgz", - "integrity": "sha512-e2i4wANQiSXgnrBlIatyHtP1odfUp0BbV5Y5nEGbxtIrStkEOAAzCUirvLBNXHLr7kwLvJl6V+4V3XV9x7Wd9w==", - "dev": true - }, - "concat-map": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", - "dev": true - }, - "diff": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", - "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", - "dev": true - }, - "escape-string-regexp": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", - "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", - "dev": true - }, - "fs.realpath": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", - "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", - "dev": true - }, - "glob": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.0.tgz", - "integrity": "sha512-lmLf6gtyrPq8tTjSmrO94wBeQbFR3HbLHbuyD69wuyQkImp2hWqMGB47OX65FBkPffO641IP9jWa1z4ivqG26Q==", - "dev": true, - "requires": { - "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^3.0.4", - "once": "^1.3.0", - "path-is-absolute": "^1.0.0" - } - }, - "has-flag": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", - "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=", - "dev": true - }, - "inflight": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", - "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", - "dev": true, - "requires": { - "once": "^1.3.0", - "wrappy": "1" - } - }, - "inherits": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", - "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", - "dev": true - }, - "minimatch": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", - "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", - "dev": true, - "requires": { - "brace-expansion": "^1.1.7" - } - }, - "once": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", - "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", - "dev": true, - "requires": { - "wrappy": "1" - } - }, - "path-is-absolute": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", - "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", - "dev": true - }, - "prettier": { - "version": "2.5.1", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.5.1.tgz", - "integrity": "sha512-vBZcPRUR5MZJwoyi3ZoyQlc1rXeEck8KgeC9AwwOn+exuxLxq5toTRDTSaVrXHxelDMHy9zlicw8u66yxoSUFg==", - "dev": true - }, - "supports-color": { - "version": "5.5.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", - "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", - "dev": true, - "requires": { - "has-flag": "^3.0.0" - } - }, - "vscode-oniguruma": { - "version": "1.6.1", - "resolved": "https://registry.npmjs.org/vscode-oniguruma/-/vscode-oniguruma-1.6.1.tgz", - "integrity": "sha512-vc4WhSIaVpgJ0jJIejjYxPvURJavX6QG41vu0mGhqywMkQqulezEqEQ3cO3gc8GvcOpX6ycmKGqRoROEMBNXTQ==", - "dev": true - }, - "vscode-textmate": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/vscode-textmate/-/vscode-textmate-7.0.1.tgz", - "integrity": "sha512-zQ5U/nuXAAMsh691FtV0wPz89nSkHbs+IQV8FDk+wew9BlSDhf4UmWGlWJfTR2Ti6xZv87Tj5fENzKf6Qk7aLw==", - "dev": true - }, - "vscode-tmgrammar-test": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/vscode-tmgrammar-test/-/vscode-tmgrammar-test-0.1.1.tgz", - "integrity": "sha512-0WvD3U+E0KV95bNT7v5g7PQ85JfAjh9MuXOy1dgwZskkCsA8ASiSy60iv30JOZrM6dBjJZooGUAybRAIB+Song==", - "dev": true, - "requires": { - "chalk": "^2.4.2", - "commander": "^9.2.0", - "diff": "^4.0.2", - "glob": "^7.1.6", - "vscode-oniguruma": "^1.5.1", - "vscode-textmate": "^7.0.1" - } - }, - "wrappy": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", + "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", "dev": true } } diff --git a/package.json b/package.json index a9145fc..bc22150 100644 --- a/package.json +++ b/package.json @@ -13,15 +13,56 @@ "url": "https://github.com/hashicorp/syntax/issues" }, "homepage": "https://github.com/hashicorp/syntax#readme", + "contributes": { + "languages": [ + { + "id": "hcl", + "extensions": [ + ".hcl" + ] + }, + { + "id": "terraform", + "extensions": [ + ".tf", + ".tfvars" + ] + }, + { + "id": "sentinel", + "extensions": [ + ".sentinel" + ] + } + ], + "grammars": [ + { + "language": "hcl", + "scopeName": "source.hcl", + "path": "syntaxes/hcl.tmGrammar.json" + }, + { + "language": "terraform", + "scopeName": "source.hcl.terraform", + "path": "syntaxes/terraform.tmGrammar.json" + }, + { + "language": "sentinel", + "scopeName": "source.sentinel", + "path": "syntaxes/sentinel.tmGrammar.json" + } + ] + }, "scripts": { "check": "prettier --check syntaxes/*.json", "format": "prettier --write syntaxes/*.json", + "build": "go run ./cmd/builder build", "test": "npm run test:snap", "test:snap": "npm run test:snap:hcl && npm run test:snap:sentinel && npm run test:snap:terraform", "test:snap:update": "npm run test:snap:hcl -- -u && npm run test:snap:sentinel -- -u && npm run test:snap:terraform -- -u", - "test:snap:hcl": "npx vscode-tmgrammar-snap -s source.hcl -g syntaxes/hcl.tmGrammar.json \"tests/snapshot/hcl/*.hcl\"", - "test:snap:sentinel": "npx vscode-tmgrammar-snap -s source.sentinel -g syntaxes/sentinel.tmGrammar.json \"tests/snapshot/sentinel/*.sentinel\"", - "test:snap:terraform": "npx vscode-tmgrammar-snap -s source.hcl.terraform -g syntaxes/terraform.tmGrammar.json -g syntaxes/hcl.tmGrammar.json \"tests/snapshot/terraform/*.tf\"" + "test:snap:hcl": "npx vscode-tmgrammar-snap \"tests/snapshot/hcl/*.hcl\"", + "test:snap:sentinel": "npx vscode-tmgrammar-snap \"tests/snapshot/sentinel/*.sentinel\"", + "test:snap:terraform": "npx vscode-tmgrammar-snap \"tests/snapshot/terraform/*.tf\"" }, "devDependencies": { "prettier": "^2.5.1",