diff --git a/.github/workflows/linting.yml b/.github/workflows/linting.yml new file mode 100644 index 0000000..e7723a0 --- /dev/null +++ b/.github/workflows/linting.yml @@ -0,0 +1,42 @@ +name: Linting + +on: + pull_request: + push: + branches: + - master + - main + +concurrency: + group: ${{github.workflow}}-${{github.ref}} + cancel-in-progress: true + +jobs: + js: + name: "JavaScript" + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + - run: npm install + - run: npm exec prettier --check . + + format-queries: + name: Queries + runs-on: ubuntu-latest + env: + NVIM_TAG: nightly + # NVIM_TAG: stable + steps: + - uses: actions/checkout@v4 + - name: Prepare + run: | + bash ./scripts/ci-install.sh + + - name: Lint + run: | + nvim --version + nvim --headless -c "TSInstallSync query" -c "q" + nvim -l scripts/format-queries.lua + git diff --exit-code diff --git a/queries/glimmer/folds.scm b/queries/glimmer/folds.scm index cfe9d35..6502455 100644 --- a/queries/glimmer/folds.scm +++ b/queries/glimmer/folds.scm @@ -1,4 +1,5 @@ [ - (element_node (element_node_start)) - (block_statement) + (element_node + (element_node_start)) + (block_statement) ] @fold diff --git a/queries/glimmer/highlights.scm b/queries/glimmer/highlights.scm index e817620..9f11468 100644 --- a/queries/glimmer/highlights.scm +++ b/queries/glimmer/highlights.scm @@ -1,84 +1,113 @@ ; === Tag Names === - ; Tags that start with a lower case letter are HTML tags ; We'll also use this highlighting for named blocks (which start with `:`) ((tag_name) @tag - (#match? @tag "^(:)?[a-z]")) + (#lua-match? @tag "^:?[%l]")) + ; Tags that start with a capital letter are Glimmer components ((tag_name) @constructor - (#match? @constructor "^[A-Z]")) + (#lua-match? @constructor "^%u")) -(attribute_name) @property +(attribute_name) @attribute (string_literal) @string + (number_literal) @number + (boolean_literal) @boolean (concat_statement) @string ; === Block Statements === - ; Highlight the brackets (block_statement_start) @tag.delimiter + (block_statement_end) @tag.delimiter ; Highlight `if`/`each`/`let` -(block_statement_start path: (identifier) @conditional) -(block_statement_end path: (identifier) @conditional) -((mustache_statement (identifier) @conditional) - (#match? @conditional "else")) +(block_statement_start + path: (identifier) @keyword.conditional) -; == Mustache Statements === +(block_statement_end + path: (identifier) @keyword.conditional) + +((mustache_statement + (identifier) @keyword.conditional) + (#lua-match? @keyword.conditional "else")) -; Hightlight the whole statement, to color brackets and separators +; == Mustache Statements === +; Highlight the whole statement, to color brackets and separators (mustache_statement) @tag.delimiter ; An identifier in a mustache expression is a variable -((mustache_statement [ - (path_expression (identifier) @variable) - (identifier) @variable +((mustache_statement + [ + (path_expression + (identifier) @variable) + (identifier) @variable ]) - (#not-match? @variable "yield|outlet|this|else")) + (#not-any-of? @variable "yield" "outlet" "this" "else")) + ; As are arguments in a block statement -(block_statement_start argument: [ - (path_expression (identifier) @variable) - (identifier) @variable +(block_statement_start + argument: [ + (path_expression + (identifier) @variable) + (identifier) @variable ]) + ; As is an identifier in a block param -(block_params (identifier) @variable) +(block_params + (identifier) @variable) + ; As are helper arguments -((helper_invocation argument: [ - (path_expression (identifier) @variable) - (identifier) @variable +((helper_invocation + argument: [ + (path_expression + (identifier) @variable) + (identifier) @variable ]) - (#not-match? @variable "this")) + (#not-eq? @variable "this")) + ; `this` should be highlighted as a built-in variable ((identifier) @variable.builtin - (#match? @variable.builtin "this")) + (#eq? @variable.builtin "this")) ; If the identifier is just "yield" or "outlet", it's a keyword -((mustache_statement (identifier) @keyword) - (#match? @keyword "yield|outlet")) +((mustache_statement + (identifier) @keyword) + (#any-of? @keyword "yield" "outlet")) ; Helpers are functions -((helper_invocation helper: [ - (path_expression (identifier) @function) - (identifier) @function +((helper_invocation + helper: [ + (path_expression + (identifier) @function) + (identifier) @function ]) - (#not-match? @function "if|yield")) -((helper_invocation helper: (identifier) @conditional) - (#match? @conditional "if")) -((helper_invocation helper: (identifier) @keyword) - (#match? @keyword "yield")) + (#not-any-of? @function "if" "yield")) + +((helper_invocation + helper: (identifier) @keyword.conditional) + (#eq? @keyword.conditional "if")) + +((helper_invocation + helper: (identifier) @keyword) + (#eq? @keyword "yield")) + +(hash_pair + key: (identifier) @property) -(hash_pair key: (identifier) @property) +(comment_statement) @comment @spell -(comment_statement) @comment +(attribute_node + "=" @operator) -(attribute_node "=" @operator) +(block_params + "as" @keyword) -(block_params "as" @keyword) -(block_params "|" @operator) +(block_params + "|" @operator) [ "<" diff --git a/queries/glimmer/indents.scm b/queries/glimmer/indents.scm index 597a0fa..c1ef130 100644 --- a/queries/glimmer/indents.scm +++ b/queries/glimmer/indents.scm @@ -1,22 +1,34 @@ [ - (element_node (element_node_start)) + (element_node + (element_node_start)) (element_node_void) - (block_statement (block_statement_start)) + (block_statement + (block_statement_start)) (mustache_statement) ] @indent.begin -(element_node (element_node_end [">"] @indent.end)) -(element_node_void "/>" @indent.end) +(element_node + (element_node_end + ">" @indent.end)) + +(element_node_void + "/>" @indent.end) + [ - ">" - "/>" - "" + "/>" + " tags ((element_node (element_node_start (tag_name) @_tag_name - (#eq? @_tag_name "style") - ) - ) - @injection.content + (#eq? @_tag_name "style"))) @injection.content (#offset! @injection.content 0 7 0 -8) (#set! injection.language "css") - (#set! injection.include-children) -) + (#set! injection.include-children)) ;