govuk_tech_docs 6.2.4 → 6.3.0.beta

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 74dc4c44fa70d8f29bb050007da7bfc8740e690f3dda8b4220fc1cbf6246d08d
4
- data.tar.gz: 972e4b78381b8a0d07384fd65dc8a40889b56458d31e3bfca60098a053e5b794
3
+ metadata.gz: 4749230e0456525bafbee2e00579a1b1170ce58c40d33a5c00672e6d1f14e61a
4
+ data.tar.gz: fad8867ac7acfc14d5e46108dbf592705c3d527a679474f9dc421b36648d196e
5
5
  SHA512:
6
- metadata.gz: c9289ca8f68a4b0327d71355929f319dea91d1a8a72dcbb10a7190a51e6cf59f06ed5df79ed7acf3efa7989c180c29c43727931e64b8045741df4a6fa7b25495
7
- data.tar.gz: 7e02307c317a55e7075c71d537fa0e11c60c7250af9c6851f2e45e6068cb8f8fde3236f9202811049e557047c078a5bd9a48e324ff6f19ae57ae651b4f556dae
6
+ metadata.gz: b38a0ea5499072b25c6500ef301958482189bd65a33766158061a8dc4c8af6625095d5ff807d28b2bd50610068c9f27d6dd845c45b070574a39abce5a346ddc2
7
+ data.tar.gz: a0d16ce398a23cfa9ee149ee2993522d13e72754931fe480e518f4ef8ee3bbee44c26eedc17c7e93c116705f077061b81a97be0746b1da53b66378dc28b12352
@@ -13,7 +13,7 @@ jobs:
13
13
  runs-on: ubuntu-latest
14
14
  steps:
15
15
  - name: 'Checkout Repository'
16
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
16
+ uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
17
17
  - name: 'Dependency Review'
18
18
  uses: actions/dependency-review-action@a1d282b36b6f3519aa1f3fc636f609c47dddb294 #5.0.0
19
19
  with:
@@ -16,7 +16,7 @@ jobs:
16
16
  go: ${{ steps.gem_version.outputs.new_version }}
17
17
 
18
18
  steps:
19
- - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
19
+ - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
20
20
  with:
21
21
  show-progress: false
22
22
 
@@ -48,7 +48,7 @@ jobs:
48
48
  if: needs.pre.outputs.go == 'true'
49
49
 
50
50
  steps:
51
- - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
51
+ - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
52
52
  with:
53
53
  show-progress: false
54
54
 
@@ -22,7 +22,7 @@ jobs:
22
22
  ruby: ['3.3', '3.4', '4.0']
23
23
 
24
24
  steps:
25
- - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
25
+ - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
26
26
  with:
27
27
  show-progress: false
28
28
 
data/.rubocop.yml CHANGED
@@ -3,7 +3,7 @@ inherit_gem:
3
3
  - config/default.yml
4
4
 
5
5
  AllCops:
6
- TargetRubyVersion: 3.1
6
+ TargetRubyVersion: 3.3.0
7
7
 
8
8
  Layout/HeredocIndentation:
9
9
  Enabled: false
@@ -13,3 +13,7 @@ Naming/HeredocDelimiterNaming:
13
13
 
14
14
  Lint/NestedMethodDefinition:
15
15
  Enabled: false
16
+
17
+ Lint/MissingSuper:
18
+ Exclude:
19
+ - 'lib/tasks/**/*'
data/.vale.ini ADDED
@@ -0,0 +1,10 @@
1
+ StylesPath = styles
2
+ Packages = https://github.com/alphagov/tech-docs-linter/releases/latest/download/tech-writing-style-guide.zip
3
+ SkippedScopes = pre, code, script, style
4
+ MinAlertLevel = suggestion
5
+ [*.{md,org,txt,erb,html}]
6
+
7
+ BasedOnStyles = tech-writing-style-guide
8
+ TokenIgnores = `[^`]+`
9
+
10
+ ; full docs about vale.ini options are at https://vale.sh/docs/vale-ini
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## 6.3.0.beta
2
+
3
+ - Add `exe/tech_docs_jobs` to allow executable `Rake` commands
4
+ - Add `rake task` for style guide linting
5
+ - Add `lib/tasks/helpers/linter_report.rb` and `lib/tasks/helpers/vale_report.rb` for formatting output
6
+ - Add `.vale.ini` to include [`tech-docs-linter`](https://github.com/alphagov/tech-docs-linter/tree/main#rules) rules
7
+ - Update `README.md`
8
+
1
9
  ## 6.2.4
2
10
 
3
11
  - Support non-JSON response content types in OpenAPI renderer.
data/README.md CHANGED
@@ -1,9 +1,11 @@
1
1
  # Tech Docs Template - gem
2
2
 
3
- This repo contains the Ruby gem that distributes the [Tech Docs Template][tdt-template]. The Tech Docs Template is a [middleman template][mmt] that
3
+ This repo contains the Ruby gem that distributes the [Tech Docs Template][tdt-template]. The Tech Docs Template is
4
+ a [middleman template][mmt] that
4
5
  you can use to build technical documentation using a GOV.UK style.
5
6
 
6
- To find out more about setting up and managing content for a website using this template, see the [Tech Docs Template documentation][tdt-docs].
7
+ To find out more about setting up and managing content for a website using this template, see
8
+ the [Tech Docs Template documentation][tdt-docs].
7
9
 
8
10
  ## Contributing
9
11
 
@@ -11,17 +13,54 @@ Everybody who uses this project is encouraged to contribute.
11
13
 
12
14
  Find out how to [contribute](https://tdt-documentation.london.cloudapps.digital/support/#contribute).
13
15
 
16
+ ## Rake tasks
17
+
18
+ This gem contains `Rake` tasks that you can use to run the linter against your middleman build. To list the available
19
+ jobs you can run the command:
20
+
21
+ ```shell
22
+ bundle exec tech_docs_jobs -T
23
+ ```
24
+
25
+ ### Tech-docs-linter
26
+
27
+ The `tech-docs-linter` is a set of `Vale` linting rules which can help you check your content meets the gov.uk style
28
+ guide. To find out more about the linter visit the [GitHub repository](https://github.com/alphagov/tech-docs-linter).
29
+ `Vale` is designed to evaluate written content, and does not recommend auto-fixing. You should review the output report
30
+ and manually resolve alerts where appropriate.
31
+
32
+ The `vale:lint` task returns a 0 exit code unless there is an `Exception`. This allows you to run the linter without interrupting your `CI/CD workflows`.
33
+
34
+ You can run the linting task from your project root with the command:
35
+
36
+ ```shell
37
+ bundle exec tech_docs_jobs lint:vale
38
+ ```
39
+
40
+ The linting job can take the following optional parameters:
41
+
42
+ | Name | Definition | Default |
43
+ |---------------|---------------------------------------------------------------------------------------------|-----------|
44
+ | `target` | Directory of your middleman build, relative to the root of your project. | './build' |
45
+ | `clean_build` | If true runs `bundle exec middleman build` to create a clean build. | 'true' |
46
+ | `full_output` | If true the full report is printed to the console, otherwise only the summary is displayed. | 'true' |
47
+
14
48
  ## GOV.UK frontend
15
49
 
16
- This gem uses [GOV.UK Frontend](https://github.com/alphagov/govuk-frontend), part of the [GOV.UK Design System](https://design-system.service.gov.uk/).
50
+ This gem uses [GOV.UK Frontend](https://github.com/alphagov/govuk-frontend), part of
51
+ the [GOV.UK Design System](https://design-system.service.gov.uk/).
17
52
 
18
- This gem can also use [GOV.UK Design System nunjucks components](https://design-system.service.gov.uk/components/). It is recommended that you use these as they are user researched and accessibility tested. An example using the `govukButton` component is available in the [example site in this gem](./example/source/index.html.md.erb).
53
+ This gem can also use [GOV.UK Design System nunjucks components](https://design-system.service.gov.uk/components/). It
54
+ is recommended that you use these as they are user researched and accessibility tested. An example using the
55
+ `govukButton` component is available in the [example site in this gem](./example/source/index.html.md.erb).
19
56
 
20
- We use `npm` to download the govuk-frontend package. To update to a new version, change the version in the [package.json file](package.json) and run `npm update`.
57
+ We use `npm` to download the govuk-frontend package. To update to a new version, change the version in
58
+ the [package.json file](package.json) and run `npm update`.
21
59
 
22
60
  ## Table of contents helper functions
23
61
 
24
- With `Middleman` you can apply layouts to group pages and customise sites. This gem has the following additional helper functions to manage the table of contents (ToC):
62
+ With `Middleman` you can apply layouts to group pages and customise sites. This gem has the following additional helper
63
+ functions to manage the table of contents (ToC):
25
64
 
26
65
  - `single_page_table_of_contents` to create a ToC from the headings on the current page
27
66
  - `multi_page_table_of_contents` to create a ToC for a group of pages, opened at the current page
@@ -48,7 +87,7 @@ end
48
87
  %>
49
88
  ```
50
89
 
51
- This example will create a ToC containing the current page title, and nested headings to a depth of 2.
90
+ This example will create a ToC containing the current page title, and nested headings to a depth of 2.
52
91
 
53
92
  ### Multi page table of contents
54
93
 
@@ -73,7 +112,10 @@ wrap_layout :core do
73
112
  end
74
113
  %>
75
114
  ```
76
- This example will create a ToC containing the page title of each resource, as a heading. Each heading can be expanded to show nested headings to the depth defined in the site config. If `include_child_resources` is set to `true`, child resources will also be included.
115
+
116
+ This example will create a ToC containing the page title of each resource, as a heading. Each heading can be expanded to
117
+ show nested headings to the depth defined in the site config. If `include_child_resources` is set to `true`, child
118
+ resources will also be included.
77
119
 
78
120
  ## Developing locally
79
121
 
@@ -90,9 +132,11 @@ To see how your changes to the gem affect your website, point your website's Gem
90
132
  gem 'govuk_tech_docs', path: '../tech-docs-gem'
91
133
  ```
92
134
 
93
- To preview your documentation changes locally, see the [Tech Docs Template documentation on previewing your documentation](https://tdt-documentation.london.cloudapps.digital/create_project/preview/#preview-your-documentation).
135
+ To preview your documentation changes locally, see
136
+ the [Tech Docs Template documentation on previewing your documentation](https://tdt-documentation.london.cloudapps.digital/create_project/preview/#preview-your-documentation).
94
137
 
95
- If you experience [the FFI gem issue for Mojave users](https://github.com/alphagov/tech-docs-gem/issues/254), you should refer to this [list of possible fixes](#issue-with-ffi-on-osx-mohave).
138
+ If you experience [the FFI gem issue for Mojave users](https://github.com/alphagov/tech-docs-gem/issues/254), you should
139
+ refer to this [list of possible fixes](#issue-with-ffi-on-osx-mohave).
96
140
 
97
141
  ### Use the example in this repo
98
142
 
@@ -106,20 +150,45 @@ bundle exec middleman server
106
150
 
107
151
  See your website on `http://localhost:4567` in your browser.
108
152
 
109
- If you experience [the FFI gem issue for Mojave users](https://github.com/alphagov/tech-docs-gem/issues/254), you should refer to this [list of possible fixes](#issue-with-ffi-on-osx-mohave).
153
+ If you experience [the FFI gem issue for Mojave users](https://github.com/alphagov/tech-docs-gem/issues/254), you should
154
+ refer to this [list of possible fixes](#issue-with-ffi-on-osx-mohave).
110
155
 
111
- For more information on previewing your documentation locally, see the [Tech Docs template documentation on previewing your documentation](https://tdt-documentation.london.cloudapps.digital/create_project/preview/#preview-your-documentation).
156
+ For more information on previewing your documentation locally, see
157
+ the [Tech Docs template documentation on previewing your documentation](https://tdt-documentation.london.cloudapps.digital/create_project/preview/#preview-your-documentation).
112
158
 
113
159
  ## Tests
114
160
 
115
- Use this command to run the linting and tests for the Ruby and JavaScript code:
161
+ ### Ruby tests and linting
162
+
163
+ You can run the Ruby test suite with the following command:
164
+
165
+ ```shell
166
+ bundle exec rspec
167
+ ```
168
+
169
+ To test a specific file include the filepath after `rspec`.
170
+
171
+ You can lint the ruby code with the command:
172
+
173
+ ```shell
174
+ bundle exec rubocop
175
+ ```
176
+
177
+ Rubocop can automatically fix some linting issues. If the above command has suggestions that you automatically fix them
178
+ with:
179
+
180
+ ```shell
181
+ bundle exec rubocop -a
182
+ ```
183
+
184
+ ### JavaScript tests and linting
185
+
186
+ Use this command to run the linting and tests for the JavaScript code:
116
187
 
117
188
  ```sh
118
189
  bundle exec rake
119
190
  ```
120
191
 
121
- ### JavaScript tests
122
-
123
192
  The JavaScript tests use the [Jasmine test framework][jas].
124
193
 
125
194
  You can run these tests on their own and see the results in your browser.
@@ -140,28 +209,38 @@ Users on OSX Mojave (10.14) may get this error when running `bundle exec middlem
140
209
  There are 3 possible ways to solve this. From best to worst, you can:
141
210
 
142
211
  * upgrade to macOS 10.15 (Catalina) or higher
143
- * tell rubygems not to use the system ffi by running `gem install ffi -- --disable-system-libffi` in the command line when the error shows
212
+ * tell rubygems not to use the system ffi by running `gem install ffi -- --disable-system-libffi` in the command line
213
+ when the error shows
144
214
  * pin the ffi version back to 1.12.2 by editing the Gemfile of your app
145
215
 
146
216
  ## Releasing new versions
147
217
 
148
- To release a new version, create a new pull request (PR) that updates [version.rb](lib/govuk_tech_docs/version.rb) and [CHANGELOG.md](CHANGELOG.md).
218
+ To release a new version, create a new pull request (PR) that updates [version.rb](lib/govuk_tech_docs/version.rb)
219
+ and [CHANGELOG.md](CHANGELOG.md).
149
220
 
150
- Do not include other changes in your pull request, as this makes it easier to find out what was released when. See an example of a [PR for releasing a new version](https://github.com/alphagov/tech-docs-gem/pull/15).
221
+ Do not include other changes in your pull request, as this makes it easier to find out what was released when. See an
222
+ example of a [PR for releasing a new version](https://github.com/alphagov/tech-docs-gem/pull/15).
151
223
 
152
224
  Travis will automatically release a [new version to Rubygems.org](https://rubygems.org/gems/govuk_tech_docs).
153
225
 
154
226
  ## Licence
155
227
 
156
- Unless stated otherwise, the codebase is released under [the MIT License][mit]. This covers both the codebase and any sample code in the documentation.
228
+ Unless stated otherwise, the codebase is released under [the MIT License][mit]. This covers both the codebase and any
229
+ sample code in the documentation.
157
230
 
158
- The documentation is [© Crown copyright][copyright] and available under the terms of the [Open Government 3.0][ogl] licence.
231
+ The documentation is [© Crown copyright][copyright] and available under the terms of the [Open Government 3.0][ogl]
232
+ licence.
159
233
 
160
234
  [mit]: LICENCE
235
+
161
236
  [copyright]: http://www.nationalarchives.gov.uk/information-management/re-using-public-sector-information/uk-government-licensing-framework/crown-copyright/
237
+
162
238
  [ogl]: http://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/
239
+
163
240
  [tdt-docs]: https://github.com/alphagov/tdt-documentation/
241
+
164
242
  [tdt-template]: https://github.com/alphagov/tech-docs-template
243
+
165
244
  [mmt]: https://middlemanapp.com/advanced/project_templates/
166
245
 
167
246
  [jas]: https://jasmine.github.io/
@@ -5,4 +5,4 @@ parent: /expired-page.html
5
5
 
6
6
  # This is a child of expired page
7
7
 
8
- Expired page should highlight in the navigation.
8
+ Expired page should highlight in the navigation.
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ require "rake"
3
+
4
+ Rake.application.init
5
+
6
+ Dir.glob(File.join(__dir__, "../lib/tasks/*.rake")).each { |r| load r }
7
+
8
+ Rake.application.top_level
@@ -1,3 +1,3 @@
1
1
  module GovukTechDocs
2
- VERSION = "6.2.4".freeze
2
+ VERSION = "6.3.0.beta".freeze
3
3
  end
@@ -5,6 +5,7 @@ module GovukTechDocs
5
5
  end
6
6
 
7
7
  helpers do
8
+ warn("This functionality is deprecated and will be removed in a future release. \n You should use the GOV.UK warning text component instead.")
8
9
  def warning_text(text)
9
10
  <<~EOS
10
11
  <div class="govuk-warning-text">
@@ -0,0 +1,49 @@
1
+ class LinterReport
2
+ attr_accessor :linter_raw_output, :linter_summary_report, :linter_full_report
3
+
4
+ def initialize(raw_output)
5
+ puts "#{self.class} initialized."
6
+ @linter_raw_output = raw_output
7
+ end
8
+
9
+ def format_linter_output
10
+ raise NotImplementedError, "Subclass must implement #format_linter_output"
11
+ end
12
+
13
+ def get_raw_output
14
+ raise "No raw output available. Check you have run the linter task correctly" unless @linter_raw_output
15
+
16
+ @linter_raw_output
17
+ end
18
+
19
+ def set_linter_summary_report
20
+ raise "Subclass must implement #set_linter_summary_report"
21
+ end
22
+
23
+ def get_linter_summary_report
24
+ raise "No output summary available. Check you have called set_linter_summary_report" unless @linter_summary_report
25
+
26
+ @linter_summary_report
27
+ end
28
+
29
+ def set_linter_full_report
30
+ raise "Subclass must implement #set_linter_full_report"
31
+ end
32
+
33
+ def get_linter_full_report
34
+ raise "No output detail available. Check you have called set_linter_full_report" unless @linter_full_report
35
+
36
+ @linter_full_report
37
+ end
38
+
39
+ protected
40
+
41
+ def set_output_text_color(text, severity)
42
+ case severity.downcase
43
+ when "error" then "\e[31m#{text}\e[0m" # Red
44
+ when "warning" then "\e[33m#{text}\e[0m" # Yellow
45
+ when "suggestion" then "\e[34m#{text}\e[0m" # Blue
46
+ else "\e[36m#{text}\e[0m" # Cyan
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,7 @@
1
+ def get_gem_root
2
+ Gem::Specification.find_by_name("govuk_tech_docs").gem_dir
3
+ end
4
+
5
+ def vale_config_path
6
+ File.join(get_gem_root, ".vale.ini")
7
+ end
@@ -0,0 +1,156 @@
1
+ require_relative "./linter_report"
2
+ require "json"
3
+
4
+ class ValeLinterReport < LinterReport
5
+ attr_accessor :table_rows, :linter_severity_totals, :table_column_widths, :formatter, :linter_summary_report_json, :linter_full_report_json
6
+
7
+ def format_linter_output
8
+ if @linter_raw_output.strip.empty?
9
+ @table_rows = []
10
+ @linter_severity_totals = { "error" => 0, "warning" => 0, "suggestion" => 0 }
11
+ else
12
+ set_table_rows
13
+ set_linter_severity_totals_from_rows
14
+ end
15
+
16
+ set_linter_full_report
17
+ set_linter_summary_report
18
+ set_linter_summary_report_json
19
+ end
20
+
21
+ def set_linter_full_report
22
+ add_formatted_rows_to_detail_output
23
+ end
24
+
25
+ def set_linter_summary_report
26
+ if @linter_severity_totals.nil?
27
+ set_linter_severity_totals_from_rows
28
+ end
29
+
30
+ error = @linter_severity_totals["error"]
31
+ warning = @linter_severity_totals["warning"]
32
+ suggestion = @linter_severity_totals["suggestion"]
33
+
34
+ @linter_summary_report = []
35
+
36
+ @linter_summary_report << "\n#{'=' * [0, 40].max}"
37
+ @linter_summary_report << "\e[1m Vale summary\e[0m"
38
+ @linter_summary_report << "-" * [0, 40].max
39
+ @linter_summary_report << " Errors: #{error.positive? ? set_output_text_color(error, 'error') : error}"
40
+ @linter_summary_report << " Warnings: #{warning.positive? ? set_output_text_color(warning, 'warning') : warning}"
41
+ @linter_summary_report << " Suggestions: #{suggestion.positive? ? set_output_text_color(suggestion, 'suggestion') : suggestion}"
42
+ @linter_summary_report << "-" * [0, 40].max
43
+ @linter_summary_report.join("\n")
44
+ end
45
+
46
+ def set_linter_summary_report_json
47
+ if @linter_severity_totals.nil?
48
+ set_linter_severity_totals_from_rows
49
+ end
50
+ @linter_summary_report_json = JSON.generate(@linter_severity_totals)
51
+ end
52
+
53
+ private
54
+
55
+ def set_table_column_widths
56
+ if @table_rows.nil?
57
+ set_table_rows
58
+ end
59
+
60
+ @table_column_widths = %i[file line severity message rule].each_with_object({}) do |col, acc|
61
+ all_values = @table_rows.map { |row| row[col].to_s }
62
+ acc[col] = [col.to_s.length, *all_values.map(&:length)].max
63
+ end
64
+ end
65
+
66
+ def set_table_formatter
67
+ if @table_column_widths.nil?
68
+ set_table_column_widths
69
+ end
70
+ @formatter = "%-#{@table_column_widths[:file]}s | %-#{@table_column_widths[:line]}s | %-#{@table_column_widths[:severity]}s | %-#{@table_column_widths[:message]}s | %-#{@table_column_widths[:rule]}s"
71
+ end
72
+
73
+ def add_formatted_header_to_detail_output
74
+ if @linter_full_report.nil?
75
+ @linter_full_report = []
76
+ end
77
+
78
+ header = sprintf(@formatter, "File", "Line", "Severity", "Message", "Rule")
79
+ @linter_full_report << "\e[1m🔍 Vale Style Linting Report\e[0m\n\n"
80
+ @linter_full_report << "\e[1m#{header}\e[0m"
81
+ @linter_full_report << "-" * header.gsub(/\e\[[0-9;]*m/, "").length
82
+ end
83
+
84
+ def add_formatted_rows_to_detail_output
85
+ set_table_column_widths
86
+ set_table_formatter
87
+ add_formatted_header_to_detail_output
88
+
89
+ @table_rows.each do |row|
90
+ @linter_full_report << format_row(row)
91
+ end
92
+ @linter_full_report.join("\n")
93
+ end
94
+
95
+ def set_linter_severity_totals_from_rows
96
+ if @table_rows.nil?
97
+ set_table_rows
98
+ end
99
+
100
+ default_totals = { "error" => 0, "warning" => 0, "suggestion" => 0 }
101
+
102
+ @linter_severity_totals = default_totals.merge(
103
+ @table_rows
104
+ .map { |r| r[:severity] }
105
+ .compact # drops any actual nils
106
+ .tally,
107
+ )
108
+ end
109
+
110
+ def format_row(row)
111
+ colored_severity = set_output_text_color(row[:severity].upcase, row[:severity])
112
+ severity_padding = " " * (@table_column_widths[:severity] - row[:severity].length)
113
+ padded_severity = "#{colored_severity}#{severity_padding}"
114
+
115
+ sprintf(
116
+ @formatter,
117
+ row[:file], row[:line], padded_severity, row[:message], row[:rule]
118
+ )
119
+ end
120
+
121
+ def set_table_rows
122
+ begin
123
+ rows_json = JSON.parse(@linter_raw_output)
124
+ rescue JSON::ParserError
125
+ puts "\e[Error parsing Vale payload:\e[0m\n#{@linter_raw_output}"
126
+ exit 1
127
+ end
128
+
129
+ unique_rows = []
130
+
131
+ rows_json.each do |file_path, alerts|
132
+ next if alerts.empty?
133
+
134
+ seen_messages = Set.new
135
+
136
+ alerts.each do |alert|
137
+ msg = alert["Message"]
138
+ # Vale will hilghlight every instance of an infraction, sometimes this is unhelpful. For example the acronyms rule needs to highlight an acronym is not defined in the first use
139
+ # it does not need to then point out every single time it is referenced in the document, so we check for itentical messages for specific rules
140
+ if seen_messages.include?(msg) && alert["Check"].downcase == "tech-writing-style-guide.acronyms"
141
+ next
142
+ end
143
+
144
+ seen_messages.add(msg)
145
+ unique_rows << {
146
+ file: file_path,
147
+ line: alert["Line"].to_s,
148
+ severity: alert["Severity"],
149
+ message: msg,
150
+ rule: alert["Check"],
151
+ }
152
+ end
153
+ end
154
+ @table_rows = unique_rows
155
+ end
156
+ end
@@ -0,0 +1,33 @@
1
+ # Rakefile
2
+ require "json"
3
+ require "open3"
4
+ require_relative "./helpers/rake_utils"
5
+ require_relative "./helpers/vale_report"
6
+
7
+ namespace :lint do
8
+ # task vale_sync:
9
+ desc "Run tech-docs-linter to check content against GOV.UK style guide."
10
+ task :vale, [:target, :clean_build, :full_output] do |_t, args|
11
+ args.with_defaults(target: "./build", clean_build: "true", full_output: "true")
12
+
13
+ sh "bundle exec vale sync --config='#{vale_config_path}'"
14
+
15
+ if args.clean_build == "true"
16
+ Rake::Task["middleman:build"].invoke
17
+ end
18
+
19
+ stdout, = Open3.capture3("vale --config='#{vale_config_path}' --output=JSON #{args.target}")
20
+
21
+ linter_report = ValeLinterReport.new(stdout)
22
+ linter_report.format_linter_output
23
+ if args.full_output == "true"
24
+ puts linter_report.get_linter_full_report
25
+ end
26
+ puts linter_report.get_linter_summary_report
27
+
28
+ # finish with a Ci friendly json string
29
+ linter_report.linter_summary_report_json
30
+ # Always exit 0 so individual project pipelines can evaluate the data themselves
31
+ exit 0
32
+ end
33
+ end
@@ -0,0 +1,10 @@
1
+ namespace :middleman do
2
+ desc "Delete build directory and run bundle exec middleman build"
3
+ task :build do
4
+ if Dir.exist?("./build")
5
+ puts "Target directory found at ./build. Removing old build."
6
+ FileUtils.rm_rf("./build")
7
+ end
8
+ sh "bundle exec middleman build"
9
+ end
10
+ end
data/package-lock.json CHANGED
@@ -12,7 +12,7 @@
12
12
  },
13
13
  "devDependencies": {
14
14
  "jasmine-browser-runner": "^4.0.0",
15
- "jasmine-core": "^6.0.0",
15
+ "jasmine-core": "^6.3.0",
16
16
  "standard": "^17.0.0"
17
17
  }
18
18
  },
@@ -2992,9 +2992,9 @@
2992
2992
  }
2993
2993
  },
2994
2994
  "node_modules/jasmine-core": {
2995
- "version": "6.2.0",
2996
- "resolved": "https://registry.npmjs.org/jasmine-core/-/jasmine-core-6.2.0.tgz",
2997
- "integrity": "sha512-b16WZG/pFEFj8qRW1ss7nDuNGYz9ji8BDGj7fJNrROauk5rj/diO3KPOuyIpcgUChdC+c0PfQ8iUk4nHE+EN4w==",
2995
+ "version": "6.3.0",
2996
+ "resolved": "https://registry.npmjs.org/jasmine-core/-/jasmine-core-6.3.0.tgz",
2997
+ "integrity": "sha512-eMm5qBovNjNoGOcgE/W207+wrcK5zrQv0Rg/rWGboUJUmZp0dFCpHTyjpuDAfCwRCqg7f9U2q2jtv/aUuzdCQg==",
2998
2998
  "dev": true,
2999
2999
  "license": "MIT"
3000
3000
  },
data/package.json CHANGED
@@ -13,7 +13,7 @@
13
13
  },
14
14
  "devDependencies": {
15
15
  "jasmine-browser-runner": "^4.0.0",
16
- "jasmine-core": "^6.0.0",
16
+ "jasmine-core": "^6.3.0",
17
17
  "standard": "^17.0.0"
18
18
  },
19
19
  "standard": {
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk_tech_docs
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.2.4
4
+ version: 6.3.0.beta
5
5
  platform: ruby
6
6
  authors:
7
7
  - Government Digital Service
@@ -383,7 +383,8 @@ description: Gem to distribute the GOV.UK Tech Docs Template. See https://github
383
383
  for the project.
384
384
  email:
385
385
  - govuk-dev@digital.cabinet-office.gov.uk
386
- executables: []
386
+ executables:
387
+ - tech_docs_jobs
387
388
  extensions: []
388
389
  extra_rdoc_files: []
389
390
  files:
@@ -402,6 +403,7 @@ files:
402
403
  - ".rspec"
403
404
  - ".rubocop.yml"
404
405
  - ".ruby-version"
406
+ - ".vale.ini"
405
407
  - CHANGELOG.md
406
408
  - Gemfile
407
409
  - LICENCE
@@ -440,6 +442,7 @@ files:
440
442
  - example/source/stylesheets/screen-old-ie.css.scss
441
443
  - example/source/stylesheets/screen.css.scss
442
444
  - example/source/templates/proxy_template.html.md
445
+ - exe/tech_docs_jobs
443
446
  - govuk_tech_docs.gemspec
444
447
  - lib/assets/javascripts/_analytics.js
445
448
  - lib/assets/javascripts/_govuk/modules.js
@@ -525,6 +528,11 @@ files:
525
528
  - lib/source/layouts/layout.erb
526
529
  - lib/source/search/index.html.erb
527
530
  - lib/source/stylesheets/manifest.css
531
+ - lib/tasks/helpers/linter_report.rb
532
+ - lib/tasks/helpers/rake_utils.rb
533
+ - lib/tasks/helpers/vale_report.rb
534
+ - lib/tasks/lint.rake
535
+ - lib/tasks/middleman.rake
528
536
  - node_modules/govuk-frontend/dist/govuk-prototype-kit/init.js
529
537
  - node_modules/govuk-frontend/dist/govuk-prototype-kit/init.scss
530
538
  - node_modules/govuk-frontend/dist/govuk/_base.scss