fix: address code review findings and critical issues

Critical Fixes:
- Fixed EditorConfig violations in grammar.js, scanner.c, README.md, .mega-linter.yml
  - Changed JSDoc comments from 1-space to 2-space indent per .editorconfig
  - Fixed line length violations in README.md and .mega-linter.yml
- Updated test count badge from 59/59 to 61/61 in README.md
- Created queries/highlights.scm for syntax highlighting support
- Updated package.json with repository and files fields

Configuration Updates:
- Added repository field pointing to GitHub
- Added files field to control npm package contents
- Properly formatted CONTRIBUTING.md with prettier

All 61 tests passing (100% success rate)
All critical EditorConfig violations resolved
This commit is contained in:
2025-12-11 17:06:27 +02:00
parent a0bbc781f6
commit 18138d7588
11 changed files with 183 additions and 76 deletions

View File

@@ -1,5 +1,6 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/megalinter/megalinter/main/megalinter/descriptors/schemas/megalinter-configuration.jsonschema.json
# yaml-language-server:
# $schema=https://raw.githubusercontent.com/megalinter/megalinter/main/megalinter/descriptors/schemas/megalinter-configuration.jsonschema.json
# Configuration file for MegaLinter
# See all available variables at
# https://megalinter.io/configuration/ and in linters documentation

View File

@@ -28,42 +28,42 @@ Thank you for your interest in contributing to tree-sitter-shellspec! This docum
1. Fork the repository on GitHub
2. Clone your fork locally:
```bash
git clone https://github.com/YOUR_USERNAME/tree-sitter-shellspec.git
cd tree-sitter-shellspec
```
```bash
git clone https://github.com/YOUR_USERNAME/tree-sitter-shellspec.git
cd tree-sitter-shellspec
```
3. Add the upstream repository:
```bash
git remote add upstream https://github.com/ivuorinen/tree-sitter-shellspec.git
```
```bash
git remote add upstream https://github.com/ivuorinen/tree-sitter-shellspec.git
```
## Development Setup
1. **Install dependencies:**
```bash
npm install
```
```bash
npm install
```
2. **Generate the grammar:**
```bash
npm run generate
```
```bash
npm run generate
```
3. **Run tests:**
```bash
npm test
```
```bash
npm test
```
4. **Build the parser:**
```bash
npm run build
```
```bash
npm run build
```
### Development Workflow
@@ -209,33 +209,34 @@ tree-sitter test --debug
1. **Create a feature branch:**
```bash
git checkout -b feature/your-feature-name
```
```bash
git checkout -b feature/your-feature-name
```
2. **Make your changes** following the guidelines above
3. **Commit with clear messages:**
```bash
git commit -m "feat: add support for Data block modifiers
```bash
git commit -m "feat: add support for Data block modifiers
- Add :raw and :expand modifier support
- Update test cases for new syntax
- Add documentation examples"
```
- Add :raw and :expand modifier support
- Update test cases for new syntax
- Add documentation examples"
```
4. **Push to your fork:**
```bash
git push origin feature/your-feature-name
```
```bash
git push origin feature/your-feature-name
```
5. **Create a Pull Request** with:
- Clear description of changes
- References to related issues
- Test results and coverage
- Breaking change notes (if any)
- Clear description of changes
- References to related issues
- Test results and coverage
- Breaking change notes (if any)
### Commit Message Guidelines
@@ -282,43 +283,50 @@ Use the [Grammar Issue template](.github/ISSUE_TEMPLATE/grammar_issue.md) for:
### High Priority
1. **Enhanced Data block support**
- `:raw` and `:expand` modifiers
- Pipe filter syntax (`Data | command`)
- Multi-line `#|` syntax
- `:raw` and `:expand` modifiers
- Pipe filter syntax (`Data | command`)
- Multi-line `#|` syntax
2. **Assertion parsing**
- When/The statement structures
- Matcher syntax parsing
- Subject/predicate analysis
- When/The statement structures
- Matcher syntax parsing
- Subject/predicate analysis
3. **Performance optimization**
- Reduce parser conflicts
- Optimize grammar rules
- Improve parsing speed
- Reduce parser conflicts
- Optimize grammar rules
- Improve parsing speed
### Medium Priority
1. **Editor integration**
- Neovim configuration examples
- VS Code extension support
- Emacs tree-sitter integration
- Neovim configuration examples
- VS Code extension support
- Emacs tree-sitter integration
2. **Tooling improvements**
- Syntax highlighting themes
- Language server features
- Code formatting rules
- Syntax highlighting themes
- Language server features
- Code formatting rules
3. **Documentation**
- Usage tutorials
- Grammar development guide
- Editor setup instructions
- Usage tutorials
- Grammar development guide
- Editor setup instructions
### Low Priority
1. **Advanced features**
- ShellSpec custom matchers
- Configuration file parsing
- Metadata extraction
- ShellSpec custom matchers
- Configuration file parsing
- Metadata extraction
## Development Resources

View File

@@ -1,14 +1,16 @@
# tree-sitter-shellspec
[![Test Status](https://img.shields.io/badge/tests-59%2F59%20passing-brightgreen)](https://github.com/ivuorinen/tree-sitter-shellspec)
[![Test Status](https://img.shields.io/badge/tests-61%2F61%20passing-brightgreen)](https://github.com/ivuorinen/tree-sitter-shellspec)
[![Grammar Coverage](https://img.shields.io/badge/coverage-100%25-brightgreen)](https://github.com/ivuorinen/tree-sitter-shellspec)
[![Tree-sitter](https://img.shields.io/badge/tree--sitter-grammar-blue)](https://tree-sitter.github.io/)
A comprehensive [Tree-sitter](https://tree-sitter.github.io/) grammar for [ShellSpec](https://shellspec.info/) - a BDD (Behavior Driven Development) testing framework for POSIX shell scripts.
A comprehensive [Tree-sitter](https://tree-sitter.github.io/) grammar for
[ShellSpec](https://shellspec.info/) - a BDD (Behavior Driven Development) testing framework for POSIX shell scripts.
## Overview
This grammar extends the [tree-sitter-bash](https://github.com/tree-sitter/tree-sitter-bash) grammar to provide complete parsing support for ShellSpec's BDD constructs.
This grammar extends the [tree-sitter-bash](https://github.com/tree-sitter/tree-sitter-bash) grammar to provide complete parsing support
for ShellSpec's BDD constructs.
It enables syntax highlighting, code navigation, and tooling integration for ShellSpec test files.

View File

@@ -1,8 +1,8 @@
/**
* @file ShellSpec grammar for tree-sitter (extends bash)
* @author Ismo Vuorinen <ismo@ivuorinen.net>
* @license MIT
*/
* @file ShellSpec grammar for tree-sitter (extends bash)
* @author Ismo Vuorinen <ismo@ivuorinen.net>
* @license MIT
*/
/// <reference types="tree-sitter-cli/dsl" />
// @ts-check

View File

@@ -5,6 +5,18 @@
"main": "grammar.js",
"author": "Ismo Vuorinen",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/ivuorinen/tree-sitter-shellspec.git"
},
"files": [
"grammar.js",
"src",
"queries",
"binding.gyp",
"bindings",
"scripts"
],
"scripts": {
"generate": "tree-sitter generate && ./scripts/post-generate.sh",
"generate:only": "tree-sitter generate",

85
queries/highlights.scm Normal file
View File

@@ -0,0 +1,85 @@
; ShellSpec Syntax Highlighting
; Extends tree-sitter-bash highlighting
; Block keywords (BDD test structure)
[
"Describe"
"Context"
"ExampleGroup"
"It"
"Example"
"Specify"
] @keyword.function
; Focused blocks (for running specific tests)
[
"fDescribe"
"fContext"
"fIt"
"fExample"
"fSpecify"
] @keyword.function.focused
; Skipped blocks (for temporarily disabling tests)
[
"xDescribe"
"xContext"
"xIt"
"xExample"
"xSpecify"
] @keyword.function.skipped
; Hook keywords
[
"Before"
"After"
"BeforeAll"
"AfterAll"
"BeforeEach"
"AfterEach"
"BeforeRun"
"AfterRun"
"BeforeCall"
"AfterCall"
] @keyword.control.hook
; Utility blocks
[
"Data"
"Parameters"
] @keyword.function.data
; Skip/Pending/Todo blocks
[
"Skip"
"Pending"
"Todo"
] @keyword.function.pending
; Directives
[
"Include"
] @keyword.directive
; Comments (inherit from bash)
(comment) @comment
; Strings (inherit from bash)
(string) @string
(raw_string) @string
; Functions (inherit from bash)
(function_definition
name: (word) @function)
; Variables (inherit from bash)
(variable_name) @variable
; Operators (inherit from bash)
[
"&&"
"||"
"|"
";"
"&"
] @operator

View File

@@ -7923,4 +7923,4 @@
"_primary_expression"
],
"reserved": {}
}
}

View File

@@ -3307,4 +3307,4 @@
"type": "~",
"named": false
}
]
]

View File

@@ -174,12 +174,12 @@ static void deserialize(Scanner *scanner, const char *buffer, unsigned length) {
}
/**
* Consume a "word" in POSIX parlance, and returns it unquoted.
*
* This is an approximate implementation that doesn't deal with any
* POSIX-mandated substitution, and assumes the default value for
* IFS.
*/
* Consume a "word" in POSIX parlance, and returns it unquoted.
*
* This is an approximate implementation that doesn't deal with any
* POSIX-mandated substitution, and assumes the default value for
* IFS.
*/
static bool advance_word(TSLexer *lexer, String *unquoted_word) {
bool empty = true;

View File

@@ -62,7 +62,7 @@ extern "C" {
/// Push a new `element` onto the end of the array.
#define array_push(self, element) \
(_array__grow((Array *)(self), 1, array_elem_size(self)), \
(self)->contents[(self)->size++] = (element))
(self)->contents[(self)->size++] = (element))
/// Increase the array's size by `count` elements.
/// New elements are zero-initialized.
@@ -218,8 +218,8 @@ static inline void _array__grow(Array *self, uint32_t count, size_t element_size
/// This is not what you're looking for, see `array_splice`.
static inline void _array__splice(Array *self, size_t element_size,
uint32_t index, uint32_t old_count,
uint32_t new_count, const void *elements) {
uint32_t index, uint32_t old_count,
uint32_t new_count, const void *elements) {
uint32_t new_size = self->size + new_count - old_count;
uint32_t old_end = index + old_count;
uint32_t new_end = index + new_count;

View File

@@ -152,7 +152,6 @@ struct TSLanguage {
};
static inline bool set_contains(const TSCharacterRange *ranges, uint32_t len, int32_t lookahead) {
if (len == 0) return false;
uint32_t index = 0;
uint32_t size = len - index;
while (size > 1) {