bearings 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 +31 -0
- data/LICENSE +21 -0
- data/README.md +32 -0
- data/lib/bearings/checks/code_examples.rb +80 -0
- data/lib/bearings/checks/constant_names.rb +99 -0
- data/lib/bearings/checks/diagrams.rb +63 -0
- data/lib/bearings/checks/external_links/failure.rb +3 -0
- data/lib/bearings/checks/external_links.rb +53 -0
- data/lib/bearings/checks/images.rb +120 -0
- data/lib/bearings/checks/links.rb +230 -0
- data/lib/bearings/checks/manifest_matches_disk.rb +48 -0
- data/lib/bearings/checks/readme_links.rb +103 -0
- data/lib/bearings/document.rb +9 -0
- data/lib/bearings/guide.rb +28 -0
- data/lib/bearings/html_pages/diagram_failure.rb +3 -0
- data/lib/bearings/html_pages.rb +174 -0
- data/lib/bearings/images/dimensions.rb +82 -0
- data/lib/bearings/images.rb +83 -0
- data/lib/bearings/kramdown.rb +253 -0
- data/lib/bearings/llms_txt.rb +61 -0
- data/lib/bearings/manifest/checks.rb +3 -0
- data/lib/bearings/manifest/group.rb +3 -0
- data/lib/bearings/manifest/outputs.rb +3 -0
- data/lib/bearings/manifest/page.rb +3 -0
- data/lib/bearings/manifest/parser.rb +264 -0
- data/lib/bearings/manifest/redirect.rb +3 -0
- data/lib/bearings/manifest/site.rb +3 -0
- data/lib/bearings/manifest.rb +3 -0
- data/lib/bearings/markdown_copies.rb +141 -0
- data/lib/bearings/net_http.rb +47 -0
- data/lib/bearings/output_file.rb +3 -0
- data/lib/bearings/pipeline.rb +101 -0
- data/lib/bearings/problem.rb +3 -0
- data/lib/bearings/rake.rb +318 -0
- data/lib/bearings/rbs.rb +20 -0
- data/lib/bearings/redirects.rb +103 -0
- data/lib/bearings/repo_path.rb +19 -0
- data/lib/bearings/report.rb +40 -0
- data/lib/bearings/search_index.rb +47 -0
- data/lib/bearings/server.rb +115 -0
- data/lib/bearings/site/group.rb +3 -0
- data/lib/bearings/site/page.rb +27 -0
- data/lib/bearings/site.rb +135 -0
- data/lib/bearings/sitemap.rb +57 -0
- data/lib/bearings/version.rb +5 -0
- data/lib/bearings/watch.rb +31 -0
- data/lib/bearings/writer.rb +63 -0
- data/lib/bearings.rb +20 -0
- data/sig/_private/kramdown.rbs +33 -0
- data/sig/_private/psych.rbs +50 -0
- data/sig/_private/rake.rbs +12 -0
- data/sig/_private/socket.rbs +4 -0
- data/sig/generated/bearings/checks/code_examples.rbs +35 -0
- data/sig/generated/bearings/checks/constant_names.rbs +48 -0
- data/sig/generated/bearings/checks/diagrams.rbs +39 -0
- data/sig/generated/bearings/checks/external_links/failure.rbs +2 -0
- data/sig/generated/bearings/checks/external_links.rbs +29 -0
- data/sig/generated/bearings/checks/images.rbs +59 -0
- data/sig/generated/bearings/checks/links.rbs +123 -0
- data/sig/generated/bearings/checks/manifest_matches_disk.rbs +20 -0
- data/sig/generated/bearings/checks/readme_links.rbs +46 -0
- data/sig/generated/bearings/document.rbs +2 -0
- data/sig/generated/bearings/guide.rbs +15 -0
- data/sig/generated/bearings/html_pages/diagram_failure.rbs +2 -0
- data/sig/generated/bearings/html_pages.rbs +90 -0
- data/sig/generated/bearings/images/dimensions.rbs +56 -0
- data/sig/generated/bearings/images.rbs +46 -0
- data/sig/generated/bearings/kramdown.rbs +119 -0
- data/sig/generated/bearings/llms_txt.rbs +30 -0
- data/sig/generated/bearings/manifest/checks.rbs +2 -0
- data/sig/generated/bearings/manifest/group.rbs +2 -0
- data/sig/generated/bearings/manifest/outputs.rbs +2 -0
- data/sig/generated/bearings/manifest/page.rbs +2 -0
- data/sig/generated/bearings/manifest/parser.rbs +127 -0
- data/sig/generated/bearings/manifest/redirect.rbs +2 -0
- data/sig/generated/bearings/manifest/site.rbs +2 -0
- data/sig/generated/bearings/manifest.rbs +2 -0
- data/sig/generated/bearings/markdown_copies.rbs +69 -0
- data/sig/generated/bearings/net_http.rbs +24 -0
- data/sig/generated/bearings/output_file.rbs +2 -0
- data/sig/generated/bearings/pipeline.rbs +62 -0
- data/sig/generated/bearings/problem.rbs +2 -0
- data/sig/generated/bearings/rake.rbs +156 -0
- data/sig/generated/bearings/rbs.rbs +7 -0
- data/sig/generated/bearings/redirects.rbs +44 -0
- data/sig/generated/bearings/repo_path.rbs +10 -0
- data/sig/generated/bearings/report.rbs +25 -0
- data/sig/generated/bearings/search_index.rbs +44 -0
- data/sig/generated/bearings/server.rbs +55 -0
- data/sig/generated/bearings/site/group.rbs +2 -0
- data/sig/generated/bearings/site/page.rbs +7 -0
- data/sig/generated/bearings/site.rbs +48 -0
- data/sig/generated/bearings/sitemap.rbs +22 -0
- data/sig/generated/bearings/version.rbs +5 -0
- data/sig/generated/bearings/watch.rbs +19 -0
- data/sig/generated/bearings/writer.rbs +29 -0
- data/sig/generated/bearings.rbs +4 -0
- data/sig/manual/bearings/checks/code_examples.rbs +4 -0
- data/sig/manual/bearings/checks/constant_names.rbs +4 -0
- data/sig/manual/bearings/checks/diagrams.rbs +4 -0
- data/sig/manual/bearings/checks/external_links/failure.rbs +13 -0
- data/sig/manual/bearings/checks/external_links.rbs +8 -0
- data/sig/manual/bearings/checks/images.rbs +4 -0
- data/sig/manual/bearings/checks/links.rbs +4 -0
- data/sig/manual/bearings/checks/manifest_matches_disk.rbs +4 -0
- data/sig/manual/bearings/checks/readme_links.rbs +4 -0
- data/sig/manual/bearings/checks.rbs +3 -0
- data/sig/manual/bearings/document.rbs +109 -0
- data/sig/manual/bearings/guide.rbs +8 -0
- data/sig/manual/bearings/html_pages/diagram_failure.rbs +11 -0
- data/sig/manual/bearings/html_pages.rbs +8 -0
- data/sig/manual/bearings/images/dimensions.rbs +4 -0
- data/sig/manual/bearings/images.rbs +4 -0
- data/sig/manual/bearings/kramdown.rbs +4 -0
- data/sig/manual/bearings/llms_txt.rbs +4 -0
- data/sig/manual/bearings/manifest/checks.rbs +13 -0
- data/sig/manual/bearings/manifest/group.rbs +15 -0
- data/sig/manual/bearings/manifest/outputs.rbs +11 -0
- data/sig/manual/bearings/manifest/page.rbs +19 -0
- data/sig/manual/bearings/manifest/parser.rbs +4 -0
- data/sig/manual/bearings/manifest/redirect.rbs +15 -0
- data/sig/manual/bearings/manifest/site.rbs +21 -0
- data/sig/manual/bearings/manifest.rbs +21 -0
- data/sig/manual/bearings/markdown_copies.rbs +4 -0
- data/sig/manual/bearings/net_http.rbs +4 -0
- data/sig/manual/bearings/output_file.rbs +13 -0
- data/sig/manual/bearings/pipeline.rbs +4 -0
- data/sig/manual/bearings/problem.rbs +21 -0
- data/sig/manual/bearings/rake.rbs +4 -0
- data/sig/manual/bearings/rbs.rbs +4 -0
- data/sig/manual/bearings/redirects.rbs +4 -0
- data/sig/manual/bearings/repo_path.rbs +4 -0
- data/sig/manual/bearings/report.rbs +4 -0
- data/sig/manual/bearings/search_index.rbs +4 -0
- data/sig/manual/bearings/server.rbs +4 -0
- data/sig/manual/bearings/site/group.rbs +15 -0
- data/sig/manual/bearings/site/page.rbs +39 -0
- data/sig/manual/bearings/site.rbs +17 -0
- data/sig/manual/bearings/sitemap.rbs +4 -0
- data/sig/manual/bearings/watch.rbs +4 -0
- data/sig/manual/bearings/writer.rbs +4 -0
- metadata +242 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 73ee3f1ed2fadc56af60adddd89f93951a0029e64452060d2377560f613451f2
|
|
4
|
+
data.tar.gz: e80c1b6ff7534b252fd3a49fa42ced4fb22747e1afd21b58a98d36d8a2a5e5e4
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 801f1e7c35af23a2db3608e04d167291500a668c91eeb6e32d9cb20e83cd412dd5dd16dcde40c9c054065f97c2aece8480837acdbdfb5a10231b32a0206bab27
|
|
7
|
+
data.tar.gz: d83b85ae98e7d93d94535c87ac3b72db62eed5dc3d75fe9a29afebe9272106ec73abed5c793fc236f684403527efb8e9bca09b95a5aa1c1466ce78ee557c4c69
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0 (2026-11-24)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* add OutputFile value and the writer that puts files in _site ([#29](https://github.com/bottrall/bearings/issues/29)) ([a258f1f](https://github.com/bottrall/bearings/commit/a258f1f0086a73209fb42e8e9583edf66698ad0a)), closes [#6](https://github.com/bottrall/bearings/issues/6)
|
|
9
|
+
* add Problem value with text and JSON reports ([#27](https://github.com/bottrall/bearings/issues/27)) ([8ab2a29](https://github.com/bottrall/bearings/commit/8ab2a296ab96b27fd39d788b94cd58721ddae9f7)), closes [#2](https://github.com/bottrall/bearings/issues/2)
|
|
10
|
+
* build and check bearings' own guides with bearings ([#54](https://github.com/bottrall/bearings/issues/54)) ([de934e7](https://github.com/bottrall/bearings/commit/de934e767fa6d6f7a8a8b10d8fed06a2e10e962d))
|
|
11
|
+
* build the site model from the manifest, files and a renderer ([#34](https://github.com/bottrall/bearings/issues/34)) ([0dd570b](https://github.com/bottrall/bearings/commit/0dd570be385893ac9d17464b120c7aa64069925d)), closes [#5](https://github.com/bottrall/bearings/issues/5)
|
|
12
|
+
* build the site with rake docs and check it with rake docs:check ([#47](https://github.com/bottrall/bearings/issues/47)) ([82510be](https://github.com/bottrall/bearings/commit/82510beec84ef56aaa088b17ee6a5be255f3d664)), closes [#23](https://github.com/bottrall/bearings/issues/23)
|
|
13
|
+
* check external links in an opt-in docs:check:external task ([#43](https://github.com/bottrall/bearings/issues/43)) ([2e78267](https://github.com/bottrall/bearings/commit/2e78267818c5315b238b6525b0112f64e1513e5c))
|
|
14
|
+
* check images are present, described, small enough and used ([#51](https://github.com/bottrall/bearings/issues/51)) ([61aaef5](https://github.com/bottrall/bearings/commit/61aaef54ffb4b437da9bd13d28769b265f5c97e1)), closes [#20](https://github.com/bottrall/bearings/issues/20)
|
|
15
|
+
* check that each mermaid diagram names a known type and has a title ([#50](https://github.com/bottrall/bearings/issues/50)) ([09bbaae](https://github.com/bottrall/bearings/commit/09bbaae09d5a03cbb2a9defc94605ff5a0b82df5)), closes [#21](https://github.com/bottrall/bearings/issues/21)
|
|
16
|
+
* check that every internal link and anchor resolves, in every output ([#52](https://github.com/bottrall/bearings/issues/52)) ([9ba6e98](https://github.com/bottrall/bearings/commit/9ba6e9890767cc3cea59ebc99e89936e2bbeef15)), closes [#17](https://github.com/bottrall/bearings/issues/17)
|
|
17
|
+
* check that ruby, json and yaml examples parse ([#41](https://github.com/bottrall/bearings/issues/41)) ([0bf77bc](https://github.com/bottrall/bearings/commit/0bf77bc388f688e24ff607dfb28563c569591d26))
|
|
18
|
+
* check the manifest matches disk ([#36](https://github.com/bottrall/bearings/issues/36)) ([ab06e71](https://github.com/bottrall/bearings/commit/ab06e7152587c2844a3aaea2453c1040b26638b7)), closes [#16](https://github.com/bottrall/bearings/issues/16)
|
|
19
|
+
* copy the images guides use into /assets with width and height ([#49](https://github.com/bottrall/bearings/issues/49)) ([67aaede](https://github.com/bottrall/bearings/commit/67aaede34c1d12ff0bd5737cb855bc2fce0e7851))
|
|
20
|
+
* load and validate the manifest ([#30](https://github.com/bottrall/bearings/issues/30)) ([bfeb1c8](https://github.com/bottrall/bearings/commit/bfeb1c8a1451db378e6cd6133f341a0cb96b8d50)), closes [#3](https://github.com/bottrall/bearings/issues/3)
|
|
21
|
+
* mark mermaid fences as diagrams and let a renderer draw them ([#48](https://github.com/bottrall/bearings/issues/48)) ([b006794](https://github.com/bottrall/bearings/commit/b006794c950275be5397a010ab72c2163dd229ab)), closes [#15](https://github.com/bottrall/bearings/issues/15)
|
|
22
|
+
* parse a guide into a Document and render its body ([#31](https://github.com/bottrall/bearings/issues/31)) ([3f18f44](https://github.com/bottrall/bearings/commit/3f18f44f2cc22841f5270505b751d71e937f6b2a)), closes [#4](https://github.com/bottrall/bearings/issues/4)
|
|
23
|
+
* render each guide through the repo's own layout ([#44](https://github.com/bottrall/bearings/issues/44)) ([0119c18](https://github.com/bottrall/bearings/commit/0119c188fcd035271bc60954d4142fa2730e17f2)), closes [#7](https://github.com/bottrall/bearings/issues/7)
|
|
24
|
+
* render GitHub alert blocks as labelled notes ([#32](https://github.com/bottrall/bearings/issues/32)) ([3164722](https://github.com/bottrall/bearings/commit/3164722722061ea5bb13c790e577c7c828aa7f18)), closes [#13](https://github.com/bottrall/bearings/issues/13)
|
|
25
|
+
* report project constants a guide names that sig/ does not declare ([#42](https://github.com/bottrall/bearings/issues/42)) ([ff65cca](https://github.com/bottrall/bearings/commit/ff65cca75f73bda1197ed280d3bbcb594b912910))
|
|
26
|
+
* serve _site/ and rebuild on change with rake docs:serve ([#53](https://github.com/bottrall/bearings/issues/53)) ([5f9a085](https://github.com/bottrall/bearings/commit/5f9a0855d19d95158959ffb8f7ce7928753444c8))
|
|
27
|
+
* write a markdown copy of every guide at /guides/<slug>.md ([#45](https://github.com/bottrall/bearings/issues/45)) ([6d9b7aa](https://github.com/bottrall/bearings/commit/6d9b7aae50a1dc8287044dfc9e75f66d67c6db90))
|
|
28
|
+
* write llms.txt and llms-full.txt from the site model ([#46](https://github.com/bottrall/bearings/issues/46)) ([f5eef5c](https://github.com/bottrall/bearings/commit/f5eef5cf7babdab63caef3438fe9fda52b94ad83))
|
|
29
|
+
* write redirect stubs from the manifest and check their targets ([#37](https://github.com/bottrall/bearings/issues/37)) ([a982041](https://github.com/bottrall/bearings/commit/a9820417196cfc8bbd14a3ba7659cbb31a9ebd87)), closes [#12](https://github.com/bottrall/bearings/issues/12)
|
|
30
|
+
* write search.json with an entry per section ([#38](https://github.com/bottrall/bearings/issues/38)) ([28be1d1](https://github.com/bottrall/bearings/commit/28be1d1d2a87685be160b69f026e007d4490897c))
|
|
31
|
+
* write sitemap.xml and robots.txt from the site model ([#35](https://github.com/bottrall/bearings/issues/35)) ([bfb3821](https://github.com/bottrall/bearings/commit/bfb38218d47555dc3a99afca438b881d6fbb6752))
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Jake Bottrall
|
|
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,32 @@
|
|
|
1
|
+
# bearings
|
|
2
|
+
|
|
3
|
+
A themeless docs engine: plain markdown guides in, a checked static site and llms.txt out.
|
|
4
|
+
|
|
5
|
+
You write the guides as plain markdown that reads the same on GitHub, list them in one manifest, and write the layout that gives the site its look. bearings builds the pages, a markdown copy of each, `llms.txt`, a search index and a sitemap, and checks every link, anchor, code example, constant name, image and diagram in them. If the check passes, the site is correct.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Add the gem to your `Gemfile`:
|
|
10
|
+
|
|
11
|
+
```ruby
|
|
12
|
+
gem 'bearings'
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Requires Ruby 3.3 or later.
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
Add two lines to your `Rakefile`:
|
|
20
|
+
|
|
21
|
+
```ruby
|
|
22
|
+
require 'bearings/rake'
|
|
23
|
+
Bearings::Rake.install
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Then `bundle exec rake docs` builds the site into `_site/`, and `bundle exec rake docs:check` builds and checks it.
|
|
27
|
+
|
|
28
|
+
## Guides
|
|
29
|
+
|
|
30
|
+
The guides are at [bearings.bottrall.dev](https://bearings.bottrall.dev), built by bearings from the markdown in this repo's `docs/` folder. Start with [Getting started](docs/GETTING_STARTED.md).
|
|
31
|
+
|
|
32
|
+
[CONTRIBUTING.md](CONTRIBUTING.md) explains the setup and the `bin/` scripts. Released under the [MIT License](LICENSE).
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'json'
|
|
4
|
+
require 'prism'
|
|
5
|
+
require 'psych'
|
|
6
|
+
|
|
7
|
+
module Bearings::Checks::CodeExamples
|
|
8
|
+
extend self
|
|
9
|
+
|
|
10
|
+
# @rbs!
|
|
11
|
+
# type failure = [Integer, String]
|
|
12
|
+
|
|
13
|
+
JSON_LOCATION = / at line (\d+) column \d+\z/ #: Regexp
|
|
14
|
+
|
|
15
|
+
# @rbs site: Bearings::Site
|
|
16
|
+
# @rbs return: Array[Bearings::Problem]
|
|
17
|
+
def call(site)
|
|
18
|
+
site.pages.flat_map do |page|
|
|
19
|
+
page.document.code_blocks.filter_map { |block| problem(page.source_path, block) }
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
private
|
|
24
|
+
|
|
25
|
+
# @rbs file: String
|
|
26
|
+
# @rbs block: Bearings::Document::CodeBlock
|
|
27
|
+
# @rbs return: Bearings::Problem?
|
|
28
|
+
def problem(file, block)
|
|
29
|
+
found = failure(block.language, block.code)
|
|
30
|
+
return unless found
|
|
31
|
+
|
|
32
|
+
line, message = found
|
|
33
|
+
Bearings::Problem.new(
|
|
34
|
+
check: 'code',
|
|
35
|
+
level: :error,
|
|
36
|
+
file:,
|
|
37
|
+
line: block.line + line,
|
|
38
|
+
message: "the #{block.language} example does not parse: #{message}",
|
|
39
|
+
hint: 'fix the example so it parses; show left-out code as a comment, not as `...`'
|
|
40
|
+
)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# @rbs language: String?
|
|
44
|
+
# @rbs code: String
|
|
45
|
+
# @rbs return: failure?
|
|
46
|
+
def failure(language, code)
|
|
47
|
+
case language
|
|
48
|
+
when 'ruby' then ruby(code)
|
|
49
|
+
when 'json' then json(code)
|
|
50
|
+
when 'yaml' then yaml(code)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# @rbs code: String
|
|
55
|
+
# @rbs return: failure?
|
|
56
|
+
def ruby(code)
|
|
57
|
+
error = Prism.parse(code).errors.first
|
|
58
|
+
[error.location.start_line, error.message] if error
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# @rbs code: String
|
|
62
|
+
# @rbs return: failure?
|
|
63
|
+
def json(code)
|
|
64
|
+
JSON.parse(code)
|
|
65
|
+
nil
|
|
66
|
+
rescue JSON::ParserError => e
|
|
67
|
+
# Older json gems, and a nesting error on any, give no line.
|
|
68
|
+
[(e.message[JSON_LOCATION, 1] || 1).to_i, e.message.sub(JSON_LOCATION, '')]
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# @rbs code: String
|
|
72
|
+
# @rbs return: failure?
|
|
73
|
+
def yaml(code)
|
|
74
|
+
# Not YAML.safe_load, which also refuses valid YAML it won't build, such as an alias or a date.
|
|
75
|
+
Psych.parse_stream(code)
|
|
76
|
+
nil
|
|
77
|
+
rescue Psych::SyntaxError => e
|
|
78
|
+
[e.line.to_i, [e.problem, e.context].compact.join(' ')]
|
|
79
|
+
end
|
|
80
|
+
end
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'did_you_mean'
|
|
4
|
+
require 'prism'
|
|
5
|
+
|
|
6
|
+
module Bearings::Checks::ConstantNames
|
|
7
|
+
extend self
|
|
8
|
+
|
|
9
|
+
# @rbs!
|
|
10
|
+
# type reference = [String, Integer]
|
|
11
|
+
# type snippet = [Prism::ProgramNode, Integer]
|
|
12
|
+
|
|
13
|
+
CONSTANT_PATH = /\A(?:::)?[A-Z]\w*(?:::[A-Z]\w*)*\z/ #: Regexp
|
|
14
|
+
|
|
15
|
+
# @rbs site: Bearings::Site
|
|
16
|
+
# @rbs declared: Set[String]
|
|
17
|
+
# @rbs return: Array[Bearings::Problem]
|
|
18
|
+
def call(site:, declared:)
|
|
19
|
+
spell_checker = DidYouMean::SpellChecker.new(dictionary: declared.to_a)
|
|
20
|
+
site.pages.flat_map do |page|
|
|
21
|
+
undeclared(page.document, site.details.namespaces, declared).map do |name, line|
|
|
22
|
+
problem(page.source_path, name, line, spell_checker.correct(name).first)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
private
|
|
28
|
+
|
|
29
|
+
# @rbs document: Bearings::Document
|
|
30
|
+
# @rbs namespaces: Array[String]
|
|
31
|
+
# @rbs declared: Set[String]
|
|
32
|
+
# @rbs return: Array[reference]
|
|
33
|
+
def undeclared(document, namespaces, declared)
|
|
34
|
+
blocks = document.code_blocks.select { |block| block.language == 'ruby' }
|
|
35
|
+
examples = blocks.map { |block| [Prism.parse(block.code).value, block.line + 1] } #: Array[snippet]
|
|
36
|
+
spans = document.code_spans.map { |span| [Prism.parse(span.code).value, span.line] } #: Array[snippet]
|
|
37
|
+
known = declared + examples.flat_map { |tree, _| definitions(tree, nil) }
|
|
38
|
+
scopes = namespaces.map { |namespace| "#{namespace}::" }
|
|
39
|
+
[*examples, *spans].flat_map { |tree, first_line| references(tree, first_line) }.uniq.select do |name, _|
|
|
40
|
+
"#{name}::".start_with?(*scopes) && !known.include?(name)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# @rbs node: Prism::node
|
|
45
|
+
# @rbs scope: String?
|
|
46
|
+
# @rbs return: Array[String]
|
|
47
|
+
def definitions(node, scope)
|
|
48
|
+
name = defined_name(node, scope)
|
|
49
|
+
inner = node.is_a?(Prism::ClassNode) || node.is_a?(Prism::ModuleNode) ? name : scope
|
|
50
|
+
[name, *node.compact_child_nodes.flat_map { |child| definitions(child, inner) }].compact
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# @rbs node: Prism::node
|
|
54
|
+
# @rbs scope: String?
|
|
55
|
+
# @rbs return: String?
|
|
56
|
+
def defined_name(node, scope)
|
|
57
|
+
written = case node
|
|
58
|
+
when Prism::ClassNode, Prism::ModuleNode then path(node.constant_path)
|
|
59
|
+
when Prism::ConstantPathWriteNode then path(node.target)
|
|
60
|
+
when Prism::ConstantWriteNode then node.name.to_s
|
|
61
|
+
end
|
|
62
|
+
return unless written
|
|
63
|
+
|
|
64
|
+
written.start_with?('::') ? written.delete_prefix('::') : [scope, written].compact.join('::')
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# @rbs node: Prism::node
|
|
68
|
+
# @rbs first_line: Integer
|
|
69
|
+
# @rbs return: Array[reference]
|
|
70
|
+
def references(node, first_line)
|
|
71
|
+
name = path(node) if node.is_a?(Prism::ConstantReadNode) || node.is_a?(Prism::ConstantPathNode)
|
|
72
|
+
return [[name.delete_prefix('::'), first_line + node.location.start_line - 1]] if name
|
|
73
|
+
|
|
74
|
+
node.compact_child_nodes.flat_map { |child| references(child, first_line) }
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# @rbs node: Prism::node
|
|
78
|
+
# @rbs return: String?
|
|
79
|
+
def path(node)
|
|
80
|
+
# A path with a dynamic part (`config::Agent`) or one the parser recovered (`Riffer::`) is not a name.
|
|
81
|
+
node.slice[CONSTANT_PATH]
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# @rbs file: String
|
|
85
|
+
# @rbs name: String
|
|
86
|
+
# @rbs line: Integer
|
|
87
|
+
# @rbs closest: String?
|
|
88
|
+
# @rbs return: Bearings::Problem
|
|
89
|
+
def problem(file, name, line, closest)
|
|
90
|
+
Bearings::Problem.new(
|
|
91
|
+
check: 'constant',
|
|
92
|
+
level: :error,
|
|
93
|
+
file:,
|
|
94
|
+
line:,
|
|
95
|
+
message: "names `#{name}`, which the RBS signatures do not declare",
|
|
96
|
+
hint: closest ? "did you mean `#{closest}`?" : 'fix the name, or declare the constant in sig/'
|
|
97
|
+
)
|
|
98
|
+
end
|
|
99
|
+
end
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Bearings::Checks::Diagrams
|
|
4
|
+
extend self
|
|
5
|
+
|
|
6
|
+
# @rbs!
|
|
7
|
+
# type finding = [:error | :warning, String, String]
|
|
8
|
+
|
|
9
|
+
TYPES = %w[
|
|
10
|
+
architecture-beta block block-beta C4Component C4Container C4Context C4Deployment C4Dynamic classDiagram
|
|
11
|
+
classDiagram-v2 erDiagram flowchart flowchart-elk gantt gitGraph graph journey kanban mindmap packet
|
|
12
|
+
packet-beta pie quadrantChart radar-beta requirement requirementDiagram sankey sankey-beta sequenceDiagram
|
|
13
|
+
stateDiagram stateDiagram-v2 timeline treemap treemap-beta xychart xychart-beta zenuml
|
|
14
|
+
].to_set.freeze #: Set[String]
|
|
15
|
+
FRONTMATTER = /\A---[ \t]*\n.*?^---[ \t]*$/m #: Regexp
|
|
16
|
+
# Mermaid skips `%%` lines, comments and `%%{init: ...}%%` directives alike, so they may come before the type.
|
|
17
|
+
TYPE = /^[ \t]*(?!%%)(\S+)/ #: Regexp
|
|
18
|
+
ACC_TITLE = /^[ \t]*accTitle[ \t]*:/ #: Regexp
|
|
19
|
+
EMPTY = [:error, 'has an empty diagram', 'write the diagram, or remove the fence'].freeze #: finding
|
|
20
|
+
UNTYPED = [
|
|
21
|
+
:error,
|
|
22
|
+
'has a diagram whose first line names no Mermaid diagram type',
|
|
23
|
+
'start the diagram with its type, such as `flowchart LR` or `sequenceDiagram`'
|
|
24
|
+
].freeze #: finding
|
|
25
|
+
UNTITLED = [
|
|
26
|
+
:warning,
|
|
27
|
+
'has a diagram with no accTitle line, the alt text that describes it',
|
|
28
|
+
'add an `accTitle: ...` line saying what the diagram shows'
|
|
29
|
+
].freeze #: finding
|
|
30
|
+
|
|
31
|
+
# @rbs site: Bearings::Site
|
|
32
|
+
# @rbs return: Array[Bearings::Problem]
|
|
33
|
+
def call(site)
|
|
34
|
+
site.pages.flat_map do |page|
|
|
35
|
+
page.document.diagrams.flat_map { |diagram| problems(page.source_path, diagram) }
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
private
|
|
40
|
+
|
|
41
|
+
# @rbs file: String
|
|
42
|
+
# @rbs diagram: Bearings::Document::Diagram
|
|
43
|
+
# @rbs return: Array[Bearings::Problem]
|
|
44
|
+
def problems(file, diagram)
|
|
45
|
+
findings(diagram.code).map do |level, message, hint|
|
|
46
|
+
Bearings::Problem.new(check: 'diagram', level:, file:, line: diagram.line, message:, hint:)
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# @rbs code: String
|
|
51
|
+
# @rbs return: Array[finding]
|
|
52
|
+
def findings(code)
|
|
53
|
+
return [EMPTY] if code.strip.empty?
|
|
54
|
+
|
|
55
|
+
[(UNTYPED unless typed?(code)), (UNTITLED unless ACC_TITLE.match?(code))].compact
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# @rbs code: String
|
|
59
|
+
# @rbs return: bool
|
|
60
|
+
def typed?(code)
|
|
61
|
+
TYPES.include?(code.sub(FRONTMATTER, '')[TYPE, 1].to_s)
|
|
62
|
+
end
|
|
63
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Bearings::Checks::ExternalLinks
|
|
4
|
+
extend self
|
|
5
|
+
|
|
6
|
+
EXTERNAL = %r{\Ahttps?://}i #: Regexp
|
|
7
|
+
SUCCESS = 200..299 #: Range[Integer]
|
|
8
|
+
HINTS = {
|
|
9
|
+
error: 'fix or remove the link',
|
|
10
|
+
warning: 'the site may be slow or down; run the check again later'
|
|
11
|
+
}.freeze #: Hash[Symbol, String]
|
|
12
|
+
|
|
13
|
+
# @rbs site: Bearings::Site
|
|
14
|
+
# @rbs http: Bearings::_HttpClient
|
|
15
|
+
# @rbs return: Array[Bearings::Problem]
|
|
16
|
+
def call(site, http)
|
|
17
|
+
found = site.pages.flat_map do |page|
|
|
18
|
+
page.document.links.filter { |link| EXTERNAL.match?(link.href) }.map { |link| [page.source_path, link] }
|
|
19
|
+
end #: Array[[String, Bearings::Document::Link]]
|
|
20
|
+
results = found.map { |_, link| link.href }.uniq.to_h { |url| [url, http.status(url)] }
|
|
21
|
+
found.filter_map { |file, link| problem(file, link, results.fetch(link.href)) }
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
# @rbs file: String
|
|
27
|
+
# @rbs link: Bearings::Document::Link
|
|
28
|
+
# @rbs result: Integer | Bearings::Checks::ExternalLinks::Failure
|
|
29
|
+
# @rbs return: Bearings::Problem?
|
|
30
|
+
def problem(file, link, result)
|
|
31
|
+
case result
|
|
32
|
+
when SUCCESS then nil
|
|
33
|
+
when Integer then failed(file, link, :error, "returned HTTP #{result}")
|
|
34
|
+
else failed(file, link, result.timed_out ? :warning : :error, "could not be fetched: #{result.reason}")
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# @rbs file: String
|
|
39
|
+
# @rbs link: Bearings::Document::Link
|
|
40
|
+
# @rbs level: :error | :warning
|
|
41
|
+
# @rbs outcome: String
|
|
42
|
+
# @rbs return: Bearings::Problem
|
|
43
|
+
def failed(file, link, level, outcome)
|
|
44
|
+
Bearings::Problem.new(
|
|
45
|
+
check: 'external-links',
|
|
46
|
+
level:,
|
|
47
|
+
file:,
|
|
48
|
+
line: link.line,
|
|
49
|
+
message: "#{link.href} #{outcome}",
|
|
50
|
+
hint: HINTS.fetch(level)
|
|
51
|
+
)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Bearings::Checks::Images
|
|
4
|
+
extend self
|
|
5
|
+
|
|
6
|
+
REMOTE = %r{\A(?:https?:)?//}i #: Regexp
|
|
7
|
+
EXTENSIONS = %w[.avif .gif .jpeg .jpg .png .svg .webp].freeze #: Array[String]
|
|
8
|
+
|
|
9
|
+
# @rbs site: Bearings::Site
|
|
10
|
+
# @rbs images: Hash[String, String]
|
|
11
|
+
# @rbs watched: Array[String]
|
|
12
|
+
# @rbs limit_kb: Integer
|
|
13
|
+
# @rbs return: Array[Bearings::Problem]
|
|
14
|
+
def call(site:, images:, watched:, limit_kb:)
|
|
15
|
+
# An <img> with a srcset gives an image per URL, all on one line and with one alt text.
|
|
16
|
+
problems = site.pages.flat_map do |page|
|
|
17
|
+
page.document.images.flat_map { |image| shown(page.source_path, image, images, limit_kb) }
|
|
18
|
+
end.uniq
|
|
19
|
+
[*problems, *unused(watched, Bearings::Images.paths(site))]
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
|
|
24
|
+
# @rbs file: String
|
|
25
|
+
# @rbs image: Bearings::Document::Image
|
|
26
|
+
# @rbs images: Hash[String, String]
|
|
27
|
+
# @rbs limit_kb: Integer
|
|
28
|
+
# @rbs return: Array[Bearings::Problem]
|
|
29
|
+
def shown(file, image, images, limit_kb)
|
|
30
|
+
path = Bearings::RepoPath.resolve(file, image.src)
|
|
31
|
+
bytes = images[path] if path
|
|
32
|
+
size_kb = bytes.bytesize.fdiv(1024).ceil if bytes
|
|
33
|
+
[
|
|
34
|
+
(undescribed(file, image) if image.alt&.strip&.empty?),
|
|
35
|
+
(missing(file, image, path) if path && !bytes),
|
|
36
|
+
(oversized(file, image, size_kb, limit_kb) if size_kb && size_kb > limit_kb),
|
|
37
|
+
(remote(file, image) if REMOTE.match?(image.src))
|
|
38
|
+
].compact
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# @rbs watched: Array[String]
|
|
42
|
+
# @rbs used: Array[String]
|
|
43
|
+
# @rbs return: Array[Bearings::Problem]
|
|
44
|
+
def unused(watched, used)
|
|
45
|
+
(watched - used).select { |path| EXTENSIONS.include?(File.extname(path).downcase) }.map do |path|
|
|
46
|
+
problem(
|
|
47
|
+
level: :error,
|
|
48
|
+
file: path,
|
|
49
|
+
line: 1,
|
|
50
|
+
message: 'is in a watched folder but no guide shows it',
|
|
51
|
+
hint: 'show it in a guide, or delete it'
|
|
52
|
+
)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# @rbs file: String
|
|
57
|
+
# @rbs image: Bearings::Document::Image
|
|
58
|
+
# @rbs return: Bearings::Problem
|
|
59
|
+
def undescribed(file, image)
|
|
60
|
+
problem(
|
|
61
|
+
level: :error,
|
|
62
|
+
file:,
|
|
63
|
+
line: image.line,
|
|
64
|
+
message: 'shows an image with no alt text',
|
|
65
|
+
hint: 'describe the image in its alt text; it is all an agent or a screen reader gets'
|
|
66
|
+
)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# @rbs file: String
|
|
70
|
+
# @rbs image: Bearings::Document::Image
|
|
71
|
+
# @rbs path: String
|
|
72
|
+
# @rbs return: Bearings::Problem
|
|
73
|
+
def missing(file, image, path)
|
|
74
|
+
problem(
|
|
75
|
+
level: :error,
|
|
76
|
+
file:,
|
|
77
|
+
line: image.line,
|
|
78
|
+
message: "shows `#{image.src}`, which was not found",
|
|
79
|
+
hint: "add the image at #{path}, or fix the path"
|
|
80
|
+
)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# @rbs file: String
|
|
84
|
+
# @rbs image: Bearings::Document::Image
|
|
85
|
+
# @rbs size_kb: Integer
|
|
86
|
+
# @rbs limit_kb: Integer
|
|
87
|
+
# @rbs return: Bearings::Problem
|
|
88
|
+
def oversized(file, image, size_kb, limit_kb)
|
|
89
|
+
problem(
|
|
90
|
+
level: :error,
|
|
91
|
+
file:,
|
|
92
|
+
line: image.line,
|
|
93
|
+
message: "shows `#{image.src}`, which is #{size_kb} KB, over the #{limit_kb} KB limit",
|
|
94
|
+
hint: 'shrink or compress the image; guides may ship inside a gem, where every image adds to the download'
|
|
95
|
+
)
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
# @rbs file: String
|
|
99
|
+
# @rbs image: Bearings::Document::Image
|
|
100
|
+
# @rbs return: Bearings::Problem
|
|
101
|
+
def remote(file, image)
|
|
102
|
+
problem(
|
|
103
|
+
level: :warning,
|
|
104
|
+
file:,
|
|
105
|
+
line: image.line,
|
|
106
|
+
message: "loads `#{image.src}` from another site",
|
|
107
|
+
hint: 'add the image to the repo and point at it by a relative path; a remote image breaks offline and in the gem'
|
|
108
|
+
)
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
# @rbs level: :error | :warning
|
|
112
|
+
# @rbs file: String
|
|
113
|
+
# @rbs line: Integer
|
|
114
|
+
# @rbs message: String
|
|
115
|
+
# @rbs hint: String
|
|
116
|
+
# @rbs return: Bearings::Problem
|
|
117
|
+
def problem(level:, file:, line:, message:, hint:)
|
|
118
|
+
Bearings::Problem.new(check: 'image', level:, file:, line:, message:, hint:)
|
|
119
|
+
end
|
|
120
|
+
end
|