rubocop-katalyst 1.0.4 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5f7856ab1894339789037570d66597d5c0001d6a4fd28a2a5bb228522e251ed2
4
- data.tar.gz: 8cda1a7dd1232c75e87ca0d0ff2d05fe229e96e042737ed2839e02973741ec07
3
+ metadata.gz: 878afbb9d22a62f802f3e4379fd9a715be12dccaf4e0b3349142c67279c597a2
4
+ data.tar.gz: 5f280bcdb95e544029a7bebb381d41988ac939beca5b74c12bf4f4383be7ec32
5
5
  SHA512:
6
- metadata.gz: fb176b91189adbcaa56fce98ce71de0405d757e4766f1e5119feb63e6e9f3672b4e4bf3aa13c00115b994656f18963fbc694b546ea9ca5499f8e76905cdb4090
7
- data.tar.gz: 7f9636d40e7accedef362ebfd0e37aaf35f01113f15c8306b2e2b4797949f9d09f1ddde6eca7251e8cb588aa2b2ba171a97ba72bd76e7e9c36a62e9906a3f68d
6
+ metadata.gz: 420954d6e572772b3045b2c0ffdd4515e69cf3afb4e60956cc036cd1375cf4ba6c42ed03b70bd4c6f2ce4326b21bbe23dbc546e87472d44baad9bbe54b68310b
7
+ data.tar.gz: 0102a86810a38372d0d28b2fcc22c377da73349ec18f2e7545bb3d86abab2ca10dd8d484ef635cfbbd597dc8f5d57a8efd4cf3b62b25faa722747c39776a5e84
data/.erb-lint.yml ADDED
@@ -0,0 +1,27 @@
1
+ ---
2
+ EnableDefaultLinters: true
3
+ exclude:
4
+ - "node_modules/**/*"
5
+ - "vendor/**/*"
6
+ linters:
7
+ ErbSafety:
8
+ enabled: true
9
+ Rubocop:
10
+ enabled: true
11
+ rubocop_config:
12
+ inherit_from:
13
+ - .rubocop.yml
14
+ Layout/InitialIndentation:
15
+ Enabled: false
16
+ Layout/LineLength:
17
+ Enabled: false
18
+ Layout/TrailingEmptyLines:
19
+ Enabled: false
20
+ Lint/UselessAssignment:
21
+ Enabled: false
22
+ Naming/FileName:
23
+ Enabled: false
24
+ Rails/OutputSafety:
25
+ Enabled: false
26
+ Style/FrozenStringLiteralComment:
27
+ Enabled: false
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## [1.1.0] - 2023-05-19
2
+
3
+ - Add erb_lint rake task and config (optional dependency)
4
+ - Add prettier rake task and config (assumes yarn)
5
+
6
+ ## [1.0.5] - 2023-03-16
7
+
8
+ - Add extra prefixes for spec contexts
9
+ - Allow repeated examples in policy specs
10
+
1
11
  ## [1.0.2] - 2022-09-02
2
12
 
3
13
  - ignore multiple expectations in features and system specs
@@ -22,4 +32,3 @@
22
32
  - Initial release
23
33
  - Disable new cops by default
24
34
  - Enforce styles within the project
25
-
data/README.md CHANGED
@@ -9,7 +9,8 @@ Cops are broken down by department; a file corresponding to each department can
9
9
  Add this line to your application's Gemfile:
10
10
 
11
11
  ```ruby
12
- gem 'rubocop-katalyst', require: false
12
+ gem "rubocop-katalyst", require: false
13
+ gem "erb_lint", require: false # optional dependency
13
14
  ```
14
15
 
15
16
  And then execute:
@@ -29,6 +30,22 @@ require:
29
30
  - rubocop-katalyst
30
31
  ```
31
32
 
33
+ You can integrate this gem with Rake by adding the following to your `Rakefile`:
34
+
35
+ ```ruby
36
+ require "rubocop/katalyst/rake_task"
37
+ RuboCop::Katalyst::RakeTask.new
38
+
39
+ require "rubocop/katalyst/erb_lint_task"
40
+ RuboCop::Katalyst::ErbLintTask.new
41
+
42
+ require "rubocop/katalyst/prettier_task"
43
+ RuboCop::Katalyst::PrettierTask.new
44
+
45
+ desc "Run lint before running RSpec"
46
+ task spec: :lint
47
+ ```
48
+
32
49
  That's it. You're all set to use Katalyst's base code styles. Override what you need in your `.rubocop.yml` file as the project demands.
33
50
 
34
51
  The gem is designed for use with Rails, so if you're using this in a non-Rails environment, you can disable the Rails cops in your configuration file with:
@@ -1,6 +1,17 @@
1
1
  # RuboCop RSpec extension configuration overrides
2
2
  # https://github.com/rubocop/rubocop-rspec
3
3
 
4
+ RSpec/ContextWording:
5
+ Description: >-
6
+ Checks that context docstring starts with an allowed prefix.
7
+ Prefixes:
8
+ - after
9
+ - as
10
+ - "on"
11
+ - when
12
+ - with
13
+ - without
14
+
4
15
  RSpec/ExampleLength:
5
16
  Exclude:
6
17
  - spec/features/**/*
@@ -10,3 +21,7 @@ RSpec/MultipleExpectations:
10
21
  Exclude:
11
22
  - spec/features/**/*
12
23
  - spec/system/**/*
24
+
25
+ RSpec/RepeatedExample:
26
+ Exclude:
27
+ - spec/policies/**/*
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rake"
4
+ require "rake/tasklib"
5
+
6
+ module RuboCop
7
+ module Katalyst
8
+ # Provides a custom rake task.
9
+ #
10
+ # require 'rubocop/katalyst/erb_lint_task'
11
+ # RuboCop::Katalyst::ErbLintTask.new
12
+ class ErbLintTask < ::Rake::TaskLib
13
+ attr_accessor :verbose
14
+
15
+ def initialize(verbose: true)
16
+ super()
17
+
18
+ @verbose = verbose
19
+
20
+ desc "Run ErbLint" unless ::Rake.application.last_description
21
+ task(erb_lint: "erb_lint:lint")
22
+
23
+ setup_subtasks
24
+
25
+ task(lint: :erb_lint)
26
+ task(autocorrect: "erb_lint:autocorrect")
27
+ end
28
+
29
+ private
30
+
31
+ def run_cli(verbose, *options)
32
+ require "erb_lint/cli"
33
+
34
+ cli = ERBLint::CLI.new
35
+ puts "Running ERBLint" if verbose
36
+ result = cli.run(["--config", config.to_path, *options])
37
+ abort("ERBLint failed!") unless result
38
+ end
39
+
40
+ def setup_subtasks
41
+ namespace :erb_lint do
42
+ desc "Run erb_lint linter"
43
+ task :lint do
44
+ run_cli(verbose, "--lint-all")
45
+ end
46
+
47
+ desc "Run erb_lint autocorrect"
48
+ task :autocorrect do
49
+ run_cli(verbose, "--lint-all", "-a")
50
+ end
51
+ end
52
+ end
53
+
54
+ def config
55
+ config = Pathname.new(".erb-lint.yml")
56
+ config = default_config unless config.exist?
57
+ config
58
+ end
59
+
60
+ def default_config
61
+ Pathname.new(__dir__).join("../../.erb-lint.yml")
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,80 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rake"
4
+ require "rake/tasklib"
5
+
6
+ module RuboCop
7
+ module Katalyst
8
+ # Provides a custom rake task.
9
+ #
10
+ # require 'rubocop/katalyst/prettier_task'
11
+ # RuboCop::Katalyst::PrettierTask.new
12
+ class PrettierTask < ::Rake::TaskLib
13
+ attr_accessor :verbose
14
+
15
+ def initialize(verbose: true)
16
+ super()
17
+
18
+ @verbose = verbose
19
+
20
+ desc "Run Prettier" unless ::Rake.application.last_description
21
+ task(prettier: "prettier:lint")
22
+
23
+ task(lint: :prettier)
24
+ task(autocorrect: "prettier:autocorrect")
25
+
26
+ setup_subtasks
27
+ end
28
+
29
+ private
30
+
31
+ def yarn(*options)
32
+ sh("yarn", *options)
33
+ end
34
+
35
+ def installed?
36
+ config.exist?
37
+ end
38
+
39
+ def config
40
+ ::Rails.application.root.join(".prettierrc.json")
41
+ end
42
+
43
+ def install_prettier
44
+ yarn("add", "--dev", "prettier")
45
+ config.open("w") do |f|
46
+ f.write <<~JSON
47
+ {}
48
+ JSON
49
+ end
50
+ yarn("install")
51
+ end
52
+
53
+ def setup_subtasks
54
+ namespace :prettier do
55
+ desc "Install npm packages with yarn"
56
+ task install: :environment do
57
+ install_prettier unless installed?
58
+ end
59
+
60
+ desc "Lint JS/SCSS files using prettier"
61
+ task lint: :install do
62
+ yarn("run", "prettier", "--check", *paths)
63
+ end
64
+
65
+ desc "Autocorrect JS/SCSS files using prettier"
66
+ task autocorrect: :install do
67
+ yarn("run", "prettier", "--write", *paths)
68
+ end
69
+ end
70
+ end
71
+
72
+ def paths
73
+ %w[
74
+ app/assets/javascripts
75
+ app/assets/stylesheets
76
+ ]
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rubocop/rake_task"
4
+
5
+ module RuboCop
6
+ module Katalyst
7
+ # Provides a custom rake task.
8
+ #
9
+ # require "rubocop/katalyst/rake_task"
10
+ # RuboCop::Katalyst::RakeTask.new
11
+ class RakeTask < ::RuboCop::RakeTask
12
+ attr_accessor :verbose
13
+
14
+ def initialize(name = :rubocop, *args, &task_block)
15
+ super
16
+
17
+ task(lint: :rubocop)
18
+ task(autocorrect: "rubocop:autocorrect")
19
+ end
20
+ end
21
+ end
22
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module Katalyst
5
- VERSION = "1.0.4"
5
+ VERSION = "1.1.0"
6
6
  end
7
7
  end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ begin
4
+ require "erb_lint"
5
+ rescue LoadError
6
+ return
7
+ end
8
+
9
+ def erb_lint_config
10
+ local = Rails.application.root.join(".erb-lint.yml")
11
+ if local.exist?
12
+ local.to_path
13
+ else
14
+ Pathname.new(__dir__).join("../../.erb-lint.yml").to_path
15
+ end
16
+ end
17
+
18
+ namespace :erb_lint do
19
+ desc "Require erb_lint"
20
+ task :require do
21
+ require "erb_lint/cli"
22
+ rescue LoadError
23
+ nil
24
+ end
25
+
26
+ desc "Run erb_lint linter"
27
+ task lint: :require do
28
+ ERBLint::CLI.new.run(["--config", erb_lint_config, "--lint-all"])
29
+ end
30
+
31
+ desc "Run erb_lint autocorrect"
32
+ task autocorrect: :require do
33
+ ERBLint::CLI.new.run(["--config", erb_lint_config, "--lint-all", "-a"])
34
+ end
35
+ end
36
+
37
+ desc "Run erb_lint linter"
38
+ task erb_lint: "erb_lint:lint"
data/package.json ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "private": true,
3
+ "scripts": {
4
+ "lint": "prettier --check *.json app/assets/javascripts app/assets/stylesheets",
5
+ "autocorrect": "prettier --write *.json app/assets/javascripts app/assets/stylesheets"
6
+ },
7
+ "devDependencies": {
8
+ "prettier": "2.7.1"
9
+ }
10
+ }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-katalyst
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Katalyst Interactive
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-27 00:00:00.000000000 Z
11
+ date: 2023-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -87,6 +87,7 @@ executables: []
87
87
  extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
+ - ".erb-lint.yml"
90
91
  - CHANGELOG.md
91
92
  - LICENSE.txt
92
93
  - README.md
@@ -106,8 +107,13 @@ files:
106
107
  - lib/rubocop-katalyst.rb
107
108
  - lib/rubocop/cop/katalyst_cops.rb
108
109
  - lib/rubocop/katalyst.rb
110
+ - lib/rubocop/katalyst/erb_lint_task.rb
109
111
  - lib/rubocop/katalyst/inject.rb
112
+ - lib/rubocop/katalyst/prettier_task.rb
113
+ - lib/rubocop/katalyst/rake_task.rb
110
114
  - lib/rubocop/katalyst/version.rb
115
+ - lib/tasks/erb_lint.rake
116
+ - package.json
111
117
  homepage: https://github.com/katalyst/rubocop-katalyst
112
118
  licenses:
113
119
  - MIT
@@ -132,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
132
138
  - !ruby/object:Gem::Version
133
139
  version: '0'
134
140
  requirements: []
135
- rubygems_version: 3.1.6
141
+ rubygems_version: 3.4.12
136
142
  signing_key:
137
143
  specification_version: 4
138
144
  summary: Code standards for Katalyst