pronto-biome 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +17 -0
- data/LICENSE +21 -0
- data/README.md +104 -0
- data/lib/pronto/biome/added_line_resolver.rb +36 -0
- data/lib/pronto/biome/config.rb +59 -0
- data/lib/pronto/biome/diff_parser.rb +77 -0
- data/lib/pronto/biome/executor.rb +110 -0
- data/lib/pronto/biome/offense.rb +84 -0
- data/lib/pronto/biome/version.rb +7 -0
- data/lib/pronto/biome.rb +68 -0
- metadata +167 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 57ca77c94be204ad36c90e034a117d941bdc8ab3368e1e67d526c53361bdde1b
|
|
4
|
+
data.tar.gz: 71dbd07795b5b7ffa7b9e20606806d76a521d72f383506727886554fa397eac7
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: e1083f41cd10780e95e2c542f29484fead24417bfdfab96e2df4e89b139f7848875916e37283faaa73fcda3aaf1edfc7331f44c43a8b093487dde69e4154a639
|
|
7
|
+
data.tar.gz: c79448534bbb95e031db3a47d75e54e6a11334364545ee7205d56c9fb2abc0e6b7bb3a7ecda810984acfa74c10dbf397125a8e22454e083f832a056226ef2dbe
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
## [0.1.0] - 2026-01-09
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Pronto runner for Biome linter
|
|
15
|
+
- Support for JS, TS, JSX, TSX, JSON files
|
|
16
|
+
- Configuration via `.pronto.yml` or `.pronto_biome.yml`
|
|
17
|
+
- `BIOME_EXECUTABLE` environment variable
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Sbastien
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# pronto-biome
|
|
2
|
+
|
|
3
|
+
[](https://badge.fury.io/rb/pronto-biome)
|
|
4
|
+
[](https://github.com/Sbastien/pronto-biome/actions/workflows/ci.yml)
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
|
|
7
|
+
> [Pronto](https://github.com/prontolabs/pronto) runner for [Biome](https://biomejs.dev/) — lint only the lines you changed.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Why pronto-biome?
|
|
12
|
+
|
|
13
|
+
Traditional linters report **all errors** in modified files. This creates noise in legacy codebases and slows down code reviews.
|
|
14
|
+
|
|
15
|
+
**pronto-biome** only reports errors on the **exact lines you modified**, making it perfect for:
|
|
16
|
+
|
|
17
|
+
- 🎯 **Gradual adoption** — Introduce Biome without fixing thousands of pre-existing issues
|
|
18
|
+
- 🔍 **Focused reviews** — See only what matters in your PR
|
|
19
|
+
- 🚀 **CI integration** — Post inline comments directly on GitHub PRs
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## Installation
|
|
24
|
+
|
|
25
|
+
Add to your Gemfile:
|
|
26
|
+
|
|
27
|
+
```ruby
|
|
28
|
+
gem 'pronto-biome'
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Then install dependencies:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
bundle install
|
|
35
|
+
npm install -D @biomejs/biome # or: pnpm add -D @biomejs/biome
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## Usage
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
# Lint changes since origin/main
|
|
44
|
+
pronto run -c origin/main --runner biome
|
|
45
|
+
|
|
46
|
+
# Lint staged changes only
|
|
47
|
+
pronto run --staged --runner biome
|
|
48
|
+
|
|
49
|
+
# Post comments on GitHub PR
|
|
50
|
+
pronto run -c origin/main -f github_pr --runner biome
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## Configuration
|
|
56
|
+
|
|
57
|
+
### Option 1: `.pronto.yml` (recommended)
|
|
58
|
+
|
|
59
|
+
```yaml
|
|
60
|
+
biome:
|
|
61
|
+
biome_executable: npx biome
|
|
62
|
+
cmd_line_opts: '--config-path=custom-biome.json'
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Option 2: `.pronto_biome.yml` (takes priority)
|
|
66
|
+
|
|
67
|
+
```yaml
|
|
68
|
+
biome_executable: ./node_modules/.bin/biome
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Options
|
|
72
|
+
|
|
73
|
+
| Option | Description | Default |
|
|
74
|
+
|--------------------|--------------------------------|----------|
|
|
75
|
+
| `biome_executable` | Command to run Biome | `biome` |
|
|
76
|
+
| `cmd_line_opts` | Additional Biome CLI options | *(none)* |
|
|
77
|
+
|
|
78
|
+
> **Note:** File filtering is handled by Biome's own configuration (`biome.json`). Use Biome's `include`/`exclude` options to control which files are linted.
|
|
79
|
+
|
|
80
|
+
### Environment Variables
|
|
81
|
+
|
|
82
|
+
| Variable | Description |
|
|
83
|
+
|----------|-------------|
|
|
84
|
+
| `BIOME_EXECUTABLE` | Override the Biome executable (useful for CI/CD) |
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
## Requirements
|
|
89
|
+
|
|
90
|
+
| Dependency | Version |
|
|
91
|
+
|------------|---------|
|
|
92
|
+
| Ruby | >= 3.1 |
|
|
93
|
+
| Pronto | ~> 0.11.0 |
|
|
94
|
+
| Biome | Any version |
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
## Contributing
|
|
99
|
+
|
|
100
|
+
Bug reports and pull requests are welcome on [GitHub](https://github.com/Sbastien/pronto-biome).
|
|
101
|
+
|
|
102
|
+
## License
|
|
103
|
+
|
|
104
|
+
[MIT License](LICENSE)
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Pronto
|
|
4
|
+
class Biome < Runner
|
|
5
|
+
# Finds the first added line within a given line range in a patch.
|
|
6
|
+
#
|
|
7
|
+
# When Biome reports a diagnostic spanning multiple lines, we need to
|
|
8
|
+
# find the first added line within that range to attach the Pronto message.
|
|
9
|
+
# We search from the end of the range to find the most relevant line
|
|
10
|
+
# (typically where the error actually occurs).
|
|
11
|
+
class AddedLineResolver
|
|
12
|
+
def initialize(patch)
|
|
13
|
+
@patch = patch
|
|
14
|
+
@added_lines_by_lineno = index_added_lines
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# Finds the first added line within the given range.
|
|
18
|
+
# Returns nil if no added line exists in the range.
|
|
19
|
+
def find_in_range(line_range)
|
|
20
|
+
line_range.to_a.reverse_each do |lineno|
|
|
21
|
+
line = @added_lines_by_lineno[lineno]
|
|
22
|
+
return line if line
|
|
23
|
+
end
|
|
24
|
+
nil
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
private
|
|
28
|
+
|
|
29
|
+
def index_added_lines
|
|
30
|
+
@patch.added_lines.each_with_object({}) do |line, hash|
|
|
31
|
+
hash[line.new_lineno] = line
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'yaml'
|
|
4
|
+
|
|
5
|
+
module Pronto
|
|
6
|
+
class Biome < Runner
|
|
7
|
+
# Configuration management for pronto-biome.
|
|
8
|
+
#
|
|
9
|
+
# Configuration sources (in priority order):
|
|
10
|
+
# 1. Environment variables (highest priority)
|
|
11
|
+
# 2. .pronto_biome.yml - Runner-specific config
|
|
12
|
+
# 3. .pronto.yml under 'biome' key - Global Pronto config
|
|
13
|
+
# 4. Built-in defaults
|
|
14
|
+
#
|
|
15
|
+
# Environment variables:
|
|
16
|
+
# - BIOME_EXECUTABLE: Command to run Biome
|
|
17
|
+
#
|
|
18
|
+
# Available options:
|
|
19
|
+
# - biome_executable: Command to run Biome (default: 'biome')
|
|
20
|
+
# - cmd_line_opts: Additional CLI options for Biome
|
|
21
|
+
class Config
|
|
22
|
+
CONFIG_FILE = '.pronto_biome.yml'
|
|
23
|
+
|
|
24
|
+
attr_reader :biome_executable, :cmd_line_opts
|
|
25
|
+
|
|
26
|
+
def initialize(repo_path)
|
|
27
|
+
options = load_options(repo_path)
|
|
28
|
+
|
|
29
|
+
@biome_executable = resolve_executable(options).freeze
|
|
30
|
+
@cmd_line_opts = (options['cmd_line_opts'] || '').freeze
|
|
31
|
+
|
|
32
|
+
freeze
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
private
|
|
36
|
+
|
|
37
|
+
def load_options(repo_path)
|
|
38
|
+
pronto_config.merge(load_runner_config(repo_path))
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Global Pronto config from .pronto.yml
|
|
42
|
+
def pronto_config
|
|
43
|
+
Pronto::ConfigFile.new.to_h['biome'] || {}
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# Runner-specific config from .pronto_biome.yml
|
|
47
|
+
def load_runner_config(repo_path)
|
|
48
|
+
config_file = File.join(repo_path, CONFIG_FILE)
|
|
49
|
+
return {} unless File.exist?(config_file)
|
|
50
|
+
|
|
51
|
+
YAML.safe_load_file(config_file, permitted_classes: [Regexp]) || {}
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def resolve_executable(options)
|
|
55
|
+
ENV.fetch('BIOME_EXECUTABLE', nil) || options['biome_executable'] || 'biome'
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Pronto
|
|
4
|
+
class Biome < Runner
|
|
5
|
+
# Parses Biome's diff structure and provides access to line numbers and changes.
|
|
6
|
+
#
|
|
7
|
+
# Biome diff structure:
|
|
8
|
+
# {
|
|
9
|
+
# "dictionary" => "const x = 1;\n",
|
|
10
|
+
# "ops" => [
|
|
11
|
+
# { "equalLines" => { "line_count" => 10 } },
|
|
12
|
+
# { "diffOp" => { "delete" => { "range" => [0, 5] } } }
|
|
13
|
+
# ]
|
|
14
|
+
# }
|
|
15
|
+
class DiffParser
|
|
16
|
+
MAX_CHANGES = 3
|
|
17
|
+
|
|
18
|
+
attr_reader :first_change_line, :changes
|
|
19
|
+
|
|
20
|
+
def initialize(diagnostic)
|
|
21
|
+
@diff = diagnostic.dig('advices', 'advices', 0, 'diff')
|
|
22
|
+
@first_change_line = 1
|
|
23
|
+
@changes = []
|
|
24
|
+
@found_first_change = false
|
|
25
|
+
|
|
26
|
+
parse if valid?
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def valid? = !@diff.nil? && @diff.key?('dictionary') && @diff.key?('ops')
|
|
30
|
+
|
|
31
|
+
private
|
|
32
|
+
|
|
33
|
+
def parse
|
|
34
|
+
@current_line = 1
|
|
35
|
+
@diff['ops'].each { |op| process(op) }
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def process(op)
|
|
39
|
+
if (count = op.dig('equalLines', 'line_count'))
|
|
40
|
+
@current_line += count
|
|
41
|
+
elsif (range = op.dig('diffOp', 'equal', 'range'))
|
|
42
|
+
@current_line += newline_count(range)
|
|
43
|
+
elsif (range = op.dig('diffOp', 'delete', 'range'))
|
|
44
|
+
handle_change(:delete, range)
|
|
45
|
+
elsif (range = op.dig('diffOp', 'insert', 'range'))
|
|
46
|
+
handle_change(:insert, range)
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def handle_change(type, range)
|
|
51
|
+
unless @found_first_change
|
|
52
|
+
@first_change_line = @current_line + 1
|
|
53
|
+
@found_first_change = true
|
|
54
|
+
end
|
|
55
|
+
record_change(type, range)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def newline_count(range)
|
|
59
|
+
text = dictionary_text(range)
|
|
60
|
+
text&.count("\n") || 0
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def record_change(type, range)
|
|
64
|
+
return if @changes.size >= MAX_CHANGES
|
|
65
|
+
|
|
66
|
+
text = dictionary_text(range)
|
|
67
|
+
return unless text && !text.strip.empty?
|
|
68
|
+
|
|
69
|
+
label = type == :delete ? 'remove' : 'add'
|
|
70
|
+
change = "#{label} `#{text.inspect[1..-2]}`"
|
|
71
|
+
@changes << change unless @changes.include?(change)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def dictionary_text(range) = @diff['dictionary'][range[0]...range[1]]
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'json'
|
|
4
|
+
require 'open3'
|
|
5
|
+
require 'shellwords'
|
|
6
|
+
|
|
7
|
+
module Pronto
|
|
8
|
+
class Biome < Runner
|
|
9
|
+
# Executes Biome in batch mode and parses its JSON output.
|
|
10
|
+
#
|
|
11
|
+
# Runs Biome once on all files and groups diagnostics by file path.
|
|
12
|
+
# This is more efficient than running Biome separately for each file.
|
|
13
|
+
#
|
|
14
|
+
# Handles various edge cases:
|
|
15
|
+
# - JSON wrapped in tool output (yarn, npx, etc.)
|
|
16
|
+
# - Missing Biome executable
|
|
17
|
+
# - Invalid JSON output
|
|
18
|
+
# - Empty diagnostics
|
|
19
|
+
class Executor
|
|
20
|
+
def initialize(config, repo_path)
|
|
21
|
+
@config = config
|
|
22
|
+
@repo_path = repo_path
|
|
23
|
+
@results = nil
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Runs Biome on all given files and returns a hash of {file_path => diagnostics}.
|
|
27
|
+
# Results are cached - subsequent calls return the cached results.
|
|
28
|
+
# Returns an empty hash on any error (missing executable, invalid JSON, etc.)
|
|
29
|
+
def run(file_paths)
|
|
30
|
+
@results ||= execute_biome(file_paths)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Returns diagnostics for a specific file path.
|
|
34
|
+
def diagnostics_for(file_path)
|
|
35
|
+
return [] unless @results
|
|
36
|
+
|
|
37
|
+
@results[file_path] || []
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# Clears the result cache. Useful for testing.
|
|
41
|
+
def clear_cache
|
|
42
|
+
@results = nil
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
private
|
|
46
|
+
|
|
47
|
+
def execute_biome(file_paths)
|
|
48
|
+
return {} if file_paths.empty?
|
|
49
|
+
|
|
50
|
+
Dir.chdir(@repo_path) { run_and_parse(file_paths) }
|
|
51
|
+
rescue JSON::ParserError => e
|
|
52
|
+
log_warning("Failed to parse Biome output: #{e.message}")
|
|
53
|
+
{}
|
|
54
|
+
rescue Errno::ENOENT => e
|
|
55
|
+
log_warning("Biome executable not found (#{@config.biome_executable}): #{e.message}")
|
|
56
|
+
{}
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def run_and_parse(file_paths)
|
|
60
|
+
stdout, stderr, status = Open3.capture3(*build_command(file_paths))
|
|
61
|
+
|
|
62
|
+
log_warning("Biome stderr: #{stderr}") if stderr && !stderr.empty?
|
|
63
|
+
|
|
64
|
+
if stdout.empty?
|
|
65
|
+
log_warning("Biome exited with code #{status.exitstatus}") unless status.success?
|
|
66
|
+
return {}
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
parse_output(stdout)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def build_command(file_paths)
|
|
73
|
+
[
|
|
74
|
+
*Shellwords.split(@config.biome_executable),
|
|
75
|
+
'check',
|
|
76
|
+
*Shellwords.split(@config.cmd_line_opts),
|
|
77
|
+
'--reporter=json',
|
|
78
|
+
*file_paths
|
|
79
|
+
].reject(&:empty?)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# Parses Biome JSON output and groups diagnostics by file path.
|
|
83
|
+
#
|
|
84
|
+
# When Biome is invoked through yarn/npx, the output may include
|
|
85
|
+
# extra lines before/after the JSON. We find the JSON line by
|
|
86
|
+
# looking for a line starting with '{'.
|
|
87
|
+
def parse_output(output)
|
|
88
|
+
output.lines.each do |line|
|
|
89
|
+
next unless line.start_with?('{')
|
|
90
|
+
|
|
91
|
+
result = JSON.parse(line)
|
|
92
|
+
return group_by_file(result['diagnostics']) if result['diagnostics']
|
|
93
|
+
|
|
94
|
+
log_warning('Biome output missing diagnostics key')
|
|
95
|
+
return {}
|
|
96
|
+
end
|
|
97
|
+
{}
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def group_by_file(diagnostics)
|
|
101
|
+
diagnostics.each_with_object(Hash.new { |h, k| h[k] = [] }) do |diagnostic, grouped|
|
|
102
|
+
path = diagnostic.dig('location', 'path', 'file')
|
|
103
|
+
grouped[path] << diagnostic if path
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def log_warning(message) = warn "[pronto-biome] #{message}"
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'diff_parser'
|
|
4
|
+
|
|
5
|
+
module Pronto
|
|
6
|
+
class Biome < Runner
|
|
7
|
+
# Converts a Biome diagnostic into an offense with line range, level, and message.
|
|
8
|
+
#
|
|
9
|
+
# Biome diagnostics come in two flavors:
|
|
10
|
+
# 1. Lint errors: Have a span (byte offsets) pointing to the exact location
|
|
11
|
+
# 2. Format errors: No span, but have a diff structure showing what changed
|
|
12
|
+
class Offense
|
|
13
|
+
SEVERITY_MAP = {
|
|
14
|
+
'fatal' => :fatal,
|
|
15
|
+
'error' => :error,
|
|
16
|
+
'warning' => :warning,
|
|
17
|
+
'information' => :info,
|
|
18
|
+
'hint' => :info
|
|
19
|
+
}.freeze
|
|
20
|
+
DEFAULT_SEVERITY = :warning
|
|
21
|
+
|
|
22
|
+
attr_reader :line_range, :level, :message
|
|
23
|
+
|
|
24
|
+
def initialize(diagnostic)
|
|
25
|
+
@diagnostic = diagnostic
|
|
26
|
+
@diff_parser = nil # Lazy loaded only for format diagnostics
|
|
27
|
+
@line_range = compute_line_range
|
|
28
|
+
@level = compute_level
|
|
29
|
+
@message = compute_message
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def valid? = !@line_range.nil?
|
|
33
|
+
|
|
34
|
+
private
|
|
35
|
+
|
|
36
|
+
def compute_line_range
|
|
37
|
+
if span
|
|
38
|
+
line_range_from_span
|
|
39
|
+
elsif format_diagnostic?
|
|
40
|
+
line = diff_parser.first_change_line
|
|
41
|
+
line..line
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def span = @diagnostic.dig('location', 'span')
|
|
46
|
+
|
|
47
|
+
def source_code = @diagnostic.dig('location', 'sourceCode')
|
|
48
|
+
|
|
49
|
+
def format_diagnostic? = @diagnostic['category'] == 'format'
|
|
50
|
+
|
|
51
|
+
def diff_parser
|
|
52
|
+
@diff_parser ||= DiffParser.new(@diagnostic)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# Converts byte offsets to line numbers by counting newlines.
|
|
56
|
+
def line_range_from_span
|
|
57
|
+
return nil unless source_code
|
|
58
|
+
|
|
59
|
+
start_offset, end_offset = span
|
|
60
|
+
start_line = source_code[0...start_offset].count("\n") + 1
|
|
61
|
+
end_line = source_code[0...end_offset].count("\n") + 1
|
|
62
|
+
|
|
63
|
+
start_line..end_line
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def compute_level = SEVERITY_MAP.fetch(@diagnostic['severity'], DEFAULT_SEVERITY)
|
|
67
|
+
|
|
68
|
+
def compute_message = format_diagnostic? ? format_message : lint_message
|
|
69
|
+
|
|
70
|
+
def lint_message
|
|
71
|
+
category = @diagnostic['category'] || ''
|
|
72
|
+
description = @diagnostic['description'] || ''
|
|
73
|
+
category.empty? ? description : "#{category}: #{description}"
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def format_message
|
|
77
|
+
changes = diff_parser.changes
|
|
78
|
+
return 'File needs formatting. Run `biome check --write` to fix.' if changes.empty?
|
|
79
|
+
|
|
80
|
+
"Formatting: #{changes.join(', ')}. Run `biome check --write` to fix."
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
data/lib/pronto/biome.rb
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'pronto'
|
|
4
|
+
require_relative 'biome/version'
|
|
5
|
+
require_relative 'biome/config'
|
|
6
|
+
require_relative 'biome/executor'
|
|
7
|
+
require_relative 'biome/offense'
|
|
8
|
+
require_relative 'biome/added_line_resolver'
|
|
9
|
+
|
|
10
|
+
module Pronto
|
|
11
|
+
# Pronto runner for Biome - a fast linter/formatter for JavaScript, TypeScript, and JSON.
|
|
12
|
+
#
|
|
13
|
+
# Runs Biome in batch mode on all changed files and reports diagnostics
|
|
14
|
+
# only for lines that were added in the current diff.
|
|
15
|
+
class Biome < Runner
|
|
16
|
+
def run
|
|
17
|
+
return [] if @patches.nil? || @patches.none?
|
|
18
|
+
|
|
19
|
+
patches_to_lint = @patches.select { |patch| patch.additions.positive? }
|
|
20
|
+
|
|
21
|
+
return [] if patches_to_lint.empty?
|
|
22
|
+
|
|
23
|
+
# Run Biome once on all files (batch mode)
|
|
24
|
+
# Use relative paths so Biome returns relative paths in diagnostics
|
|
25
|
+
file_paths = patches_to_lint.map { |p| p.delta.new_file[:path] }
|
|
26
|
+
executor.run(file_paths)
|
|
27
|
+
|
|
28
|
+
patches_to_lint.flat_map { |patch| inspect(patch) }.compact
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
private
|
|
32
|
+
|
|
33
|
+
def biome_config
|
|
34
|
+
@biome_config ||= Config.new(repo_path)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def executor
|
|
38
|
+
@executor ||= Executor.new(biome_config, repo_path)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def repo_path
|
|
42
|
+
@repo_path ||= @patches.first.repo.path
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def inspect(patch)
|
|
46
|
+
# Use relative path to match Biome's output format
|
|
47
|
+
relative_path = patch.delta.new_file[:path]
|
|
48
|
+
diagnostics = executor.diagnostics_for(relative_path)
|
|
49
|
+
resolver = AddedLineResolver.new(patch)
|
|
50
|
+
|
|
51
|
+
diagnostics.flat_map do |diagnostic|
|
|
52
|
+
offense = Offense.new(diagnostic)
|
|
53
|
+
next unless offense.valid?
|
|
54
|
+
|
|
55
|
+
added_line = resolver.find_in_range(offense.line_range)
|
|
56
|
+
next unless added_line
|
|
57
|
+
|
|
58
|
+
new_message(offense, added_line)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def new_message(offense, line)
|
|
63
|
+
path = line.patch.delta.new_file[:path]
|
|
64
|
+
|
|
65
|
+
Message.new(path, line, offense.level, offense.message, nil, self.class)
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: pronto-biome
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Sbastien
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: pronto
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - "~>"
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: 0.11.0
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - "~>"
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: 0.11.0
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: base64
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '0'
|
|
33
|
+
type: :development
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '0'
|
|
40
|
+
- !ruby/object:Gem::Dependency
|
|
41
|
+
name: faraday-retry
|
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - ">="
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '0'
|
|
47
|
+
type: :development
|
|
48
|
+
prerelease: false
|
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - ">="
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '0'
|
|
54
|
+
- !ruby/object:Gem::Dependency
|
|
55
|
+
name: rake
|
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
|
57
|
+
requirements:
|
|
58
|
+
- - "~>"
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: '13.0'
|
|
61
|
+
type: :development
|
|
62
|
+
prerelease: false
|
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - "~>"
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: '13.0'
|
|
68
|
+
- !ruby/object:Gem::Dependency
|
|
69
|
+
name: rspec
|
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
|
71
|
+
requirements:
|
|
72
|
+
- - "~>"
|
|
73
|
+
- !ruby/object:Gem::Version
|
|
74
|
+
version: '3.0'
|
|
75
|
+
type: :development
|
|
76
|
+
prerelease: false
|
|
77
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
78
|
+
requirements:
|
|
79
|
+
- - "~>"
|
|
80
|
+
- !ruby/object:Gem::Version
|
|
81
|
+
version: '3.0'
|
|
82
|
+
- !ruby/object:Gem::Dependency
|
|
83
|
+
name: rubocop
|
|
84
|
+
requirement: !ruby/object:Gem::Requirement
|
|
85
|
+
requirements:
|
|
86
|
+
- - "~>"
|
|
87
|
+
- !ruby/object:Gem::Version
|
|
88
|
+
version: '1.0'
|
|
89
|
+
type: :development
|
|
90
|
+
prerelease: false
|
|
91
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
92
|
+
requirements:
|
|
93
|
+
- - "~>"
|
|
94
|
+
- !ruby/object:Gem::Version
|
|
95
|
+
version: '1.0'
|
|
96
|
+
- !ruby/object:Gem::Dependency
|
|
97
|
+
name: rubocop-rake
|
|
98
|
+
requirement: !ruby/object:Gem::Requirement
|
|
99
|
+
requirements:
|
|
100
|
+
- - "~>"
|
|
101
|
+
- !ruby/object:Gem::Version
|
|
102
|
+
version: '0.6'
|
|
103
|
+
type: :development
|
|
104
|
+
prerelease: false
|
|
105
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
106
|
+
requirements:
|
|
107
|
+
- - "~>"
|
|
108
|
+
- !ruby/object:Gem::Version
|
|
109
|
+
version: '0.6'
|
|
110
|
+
- !ruby/object:Gem::Dependency
|
|
111
|
+
name: rubocop-rspec
|
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
|
113
|
+
requirements:
|
|
114
|
+
- - "~>"
|
|
115
|
+
- !ruby/object:Gem::Version
|
|
116
|
+
version: '3.0'
|
|
117
|
+
type: :development
|
|
118
|
+
prerelease: false
|
|
119
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
120
|
+
requirements:
|
|
121
|
+
- - "~>"
|
|
122
|
+
- !ruby/object:Gem::Version
|
|
123
|
+
version: '3.0'
|
|
124
|
+
description: Pronto runner for Biome, reports only on lines changed in the diff
|
|
125
|
+
email:
|
|
126
|
+
- sbastien@users.noreply.github.com
|
|
127
|
+
executables: []
|
|
128
|
+
extensions: []
|
|
129
|
+
extra_rdoc_files: []
|
|
130
|
+
files:
|
|
131
|
+
- CHANGELOG.md
|
|
132
|
+
- LICENSE
|
|
133
|
+
- README.md
|
|
134
|
+
- lib/pronto/biome.rb
|
|
135
|
+
- lib/pronto/biome/added_line_resolver.rb
|
|
136
|
+
- lib/pronto/biome/config.rb
|
|
137
|
+
- lib/pronto/biome/diff_parser.rb
|
|
138
|
+
- lib/pronto/biome/executor.rb
|
|
139
|
+
- lib/pronto/biome/offense.rb
|
|
140
|
+
- lib/pronto/biome/version.rb
|
|
141
|
+
homepage: https://github.com/Sbastien/pronto-biome
|
|
142
|
+
licenses:
|
|
143
|
+
- MIT
|
|
144
|
+
metadata:
|
|
145
|
+
bug_tracker_uri: https://github.com/Sbastien/pronto-biome/issues
|
|
146
|
+
changelog_uri: https://github.com/Sbastien/pronto-biome/blob/main/CHANGELOG.md
|
|
147
|
+
homepage_uri: https://github.com/Sbastien/pronto-biome
|
|
148
|
+
source_code_uri: https://github.com/Sbastien/pronto-biome
|
|
149
|
+
rubygems_mfa_required: 'true'
|
|
150
|
+
rdoc_options: []
|
|
151
|
+
require_paths:
|
|
152
|
+
- lib
|
|
153
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
154
|
+
requirements:
|
|
155
|
+
- - ">="
|
|
156
|
+
- !ruby/object:Gem::Version
|
|
157
|
+
version: 3.1.0
|
|
158
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
159
|
+
requirements:
|
|
160
|
+
- - ">="
|
|
161
|
+
- !ruby/object:Gem::Version
|
|
162
|
+
version: '0'
|
|
163
|
+
requirements: []
|
|
164
|
+
rubygems_version: 3.6.9
|
|
165
|
+
specification_version: 4
|
|
166
|
+
summary: Pronto runner for Biome linter
|
|
167
|
+
test_files: []
|