rubocop-katalyst 1.0.5 → 1.1.1

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: 0d872235c01b5a23b0a7ef5ee53c6d7fff76bac0787b9cb55f67a8e12c2752c0
4
- data.tar.gz: 713155b1dd8d95262957bc30dc475d141352064cedbc68ea9f8dedb7768ced07
3
+ metadata.gz: 26fee9e8b172a6df522158a09a672c1b40eeae87b3961744a4571230de7f85d5
4
+ data.tar.gz: 851a95c37b821aa41a0e6dab73edebc08485b4f8531139be603c5f9711366bee
5
5
  SHA512:
6
- metadata.gz: d47542f7d89bf0115a61047b1ad736aa7e8768b9e5e6ea3f27c93e6c857f2496bd9d2f0daa84bb788187b7493c6072440e0fb0ca920658d126e47b198a513ef4
7
- data.tar.gz: 92e98174d9d68f21ca6b4d7667a12d654b3a7a50eda7f85575c32fa38c09fde8d5c14c9e7316b20cefcaae79809f26670f91863176163706652c0c197f2b2816
6
+ metadata.gz: 6e7566b5856e454ff68f9a953fb4962e8043aa5a960b8cfc8bcb4cdafa72de3b053bf24f64a1a9efe193c50b7d2c541854eba454b252b286baf048adf8df2ca9
7
+ data.tar.gz: '0863f83b004af228e780f1b54106ba24df85ddf991fda7b77590fc05fbb652c36510e9878cea0a116d18942f0494fa82937aa96dab6ad0ba7f191c09a0b12cf9'
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,8 @@
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
+
1
6
  ## [1.0.5] - 2023-03-16
2
7
 
3
8
  - Add extra prefixes for spec contexts
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:
@@ -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 = ::Rails.application.root.join(".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.5"
5
+ VERSION = "1.1.1"
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.5
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Katalyst Interactive
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-16 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
@@ -117,7 +123,7 @@ metadata:
117
123
  source_code_uri: https://github.com/katalyst/rubocop-katalyst
118
124
  changelog_uri: https://github.com/katalyst/rubocop-katalyst/blob/main/CHANGELOG.md
119
125
  rubygems_mfa_required: 'true'
120
- post_install_message:
126
+ post_install_message:
121
127
  rdoc_options: []
122
128
  require_paths:
123
129
  - lib
@@ -132,8 +138,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
132
138
  - !ruby/object:Gem::Version
133
139
  version: '0'
134
140
  requirements: []
135
- rubygems_version: 3.3.26
136
- signing_key:
141
+ rubygems_version: 3.4.12
142
+ signing_key:
137
143
  specification_version: 4
138
144
  summary: Code standards for Katalyst
139
145
  test_files: []