rfix 1.0.7.pre.68 → 1.0.7

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: a26f95a0567bf3581515e5f7b7acc0b020ffad71f610e64cec9314b1a128573d
4
- data.tar.gz: f70e41c32e3fe733fda2349d83c02e77705461337da6c0b5313e763c0950a46c
3
+ metadata.gz: 62646c9f16e2ab955a7a9991bdb352f746abc64fe40935748d1f46102a377a71
4
+ data.tar.gz: 4887ecd7aa14ca41aa06905d3eb2213ee91a58b9e7578e7bb0a87d30331598f3
5
5
  SHA512:
6
- metadata.gz: 325fa9f8df215013e37cb0ee1b05d969cc3c66933a52b52605bbff6a5a4061445d7bb143b05bdca7ba624a5d9aa722582df782ea211110e83fd4cecd35d3b965
7
- data.tar.gz: 255ffb2025dd390cb83939ffa90479cdb7dcd395b9f0511f9afdda54aad56c9975662c20080b575d31d4e9b9c1a35ce3f96b02629921a39684f669210f09cae3
6
+ metadata.gz: acac0bbc26cda8e39742b91abde14386c0d6cb8f252aa7de3de65c69421f93c3db4ffb3026c6763f3328f901ba148451c7c3ee1fb71ca7548d09922f0e5c9b41
7
+ data.tar.gz: b65b8dde72ab2ad7796a402d60ac2e351009adab266509797e71654129bcd7577edf821ef15bd5b6b065defaf6284a8cf7b827e975f9314146cf68772ff68a5b
@@ -1,11 +1,4 @@
1
1
  language: ruby
2
- cache:
3
- bundler: true
4
- directories:
5
- - $HOME/.rvm
6
- - $HOME/Library/Caches/Homebrew
7
- before_cache:
8
- - brew cleanup
9
2
  rvm:
10
3
  - 2.5.0
11
4
  - 2.6.2
@@ -24,7 +17,8 @@ gemfile:
24
17
  - ci/Gemfile.rubocop-0.85.1
25
18
  before_install:
26
19
  - yes | gem update --system --force
27
- - gem install bundler
20
+ - gem uninstall bundler
21
+ - gem install bundler -v 2.1.4
28
22
  - bundle config git.allow_insecure true
29
23
  install:
30
24
  - bundle install
data/README.md CHANGED
@@ -1,85 +1,39 @@
1
- # Rfix [![Build Status](https://travis-ci.org/oleander/rfix-rb.svg?branch=master)](https://travis-ci.org/oleander/rfix-rb) [![Gem](https://img.shields.io/gem/dt/rfix)](https://rubygems.org/gems/rfix)
1
+ # Rfix [![Build Status](https://travis-ci.org/oleander/rfix-rb.svg?branch=master)](https://travis-ci.org/oleander/rfix-rb) ![Gem](https://img.shields.io/gem/dt/rfix)
2
2
 
3
- RuboCop CLI that only complains about your latest changes. Includes a RuboCop formatter with syntax highlighting and build in hyperlinks for offense documentation. Supports both linting (`rfix lint`) and the RuboCops autofix feature (`rfix local|origin|branch`) for the changes you made.
4
-
5
- Supports the same CLI arguments as RuboCop. Run `rfix --help` for the complete list.
6
-
7
- ![Printscreen](resources/ps.png)
3
+ RuboCop CLI that only complains about your latest changes
8
4
 
9
5
  ## Installation
10
6
 
11
7
  ``` shell
12
- $ gem install rfix --pre
13
- ```
14
-
15
- ## Help
16
-
17
- ``` shell
18
- $ rfix branch <branch> # Fix changes made between HEAD and <branch>
19
- $ rfix origin # Fix changes made between HEAD and origin branch
20
- $ rfix local # Fix changes not yet pushed to upstream branch
21
- $ rfix info # Display runtime dependencies and their versions
22
- $ rfix all # Fix all files in this repository (not recommended)
23
- $ rfix lint # Shortcut for 'rfix local --dry --untracked'
24
- $ rfix # Displays this list of supported commands
8
+ $ gem install rfix
9
+ $ rfix <local|branch|origin|info|all> [--dry] [--help]
25
10
  ```
26
11
 
27
- ### Arguments
28
-
29
- - `--dry` Turns off RuboCops autofix feature (read-only mode)
30
- - `--help` Displays RubyCops and Rfix supported arguments
31
- - `--list-files` List all files being passed to RubyCop
32
- - `--untracked` Include files not tracked by git
33
- - `--config` Configuration file, defaults to `.rubocop.yml`
34
-
35
12
  ## Development
36
13
 
37
- ### Setup
38
-
39
- 1. Download repository
40
- 1. `$ git clone https://github.com/oleander/rfix-rb`
41
- 2. `$ cd rfix-rb`
42
- 2. Downloads fixtures and run time dependencies
43
- - `$ bundle exec rake setup`
44
-
45
- ### Install from repository
46
-
47
- ``` shell
48
- $ bundle exec rake local
49
- ```
50
-
51
- ### Run tests
52
-
53
- ``` shell
54
- $ bundle exec rake spec
55
- ```
14
+ - `git clone https://github.com/oleander/rfix-rb`
15
+ - `cd rfix-rb`
16
+ - `bundle install`
17
+ - `bundle exec rake setup`
18
+ - `bundle exec rake local`
19
+ - `bundle exec rake spec`
56
20
 
57
21
  ## Overcommit
58
22
 
59
- Add the following to your `.overcommit.yml`, then run `overcommit --install` and `overcommit --sign pre-commit`. It will lint commits not yet pushed to upstream branch everytime `git commit` is ran.
60
-
61
23
  ``` yaml
62
24
  PreCommit:
63
25
  RFix:
64
26
  enabled: true
65
- command: ["rfix", "lint"]
66
- description: "Lint unchanged commits using RuboCop"
27
+ command: ["rfix", "local", "--untracked", "--dry"]
28
+ description: "Lint changes since last push using RuboCop"
67
29
  parallelize: true
68
30
  ```
69
31
 
70
- ### From scratch
71
-
72
- 1. `gem install overcommit rfix`
73
- 2. `curl https://raw.githubusercontent.com/oleander/rfix-rb/master/resouces/overcommit.yml > .overcommit.yml`
74
- 3. `overcommit --install`
75
- 4. `overcommit --sign pre-commit`
76
-
77
- Run `overcommit --run` to test the new hook.
78
-
79
32
  ## Contributing
80
33
 
81
34
  Bug reports and pull requests are welcome on GitHub at https://github.com/oleander/rfix.
82
35
 
36
+
83
37
  ## License
84
38
 
85
39
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/exe/rfix CHANGED
@@ -20,13 +20,38 @@ CLI::UI::StdoutRouter.enable
20
20
 
21
21
  say "Using RuboCop {{yellow:#{RuboCop::Version.version}}}"
22
22
 
23
- options.on("--untracked", "Include untracked files") do
24
- Rfix.load_untracked!
23
+ base_config = {
24
+ color: true,
25
+ force_exclusion: true,
26
+ auto_correct: true,
27
+ formatters: ["Rfix::Formatter"]
28
+ }
29
+
30
+ # For version 0.80.x .. 0.83.x:
31
+ # Otherwise it will exit with status code = 1
32
+ if (0.80..0.83).include?(RuboCop::Version::STRING.to_f)
33
+ if is_dry
34
+ base_config[:fail_level] = :autocorrect
35
+ else
36
+ base_config[:fail_level] = :warning
37
+ end
38
+ end
39
+
40
+ def load_config
41
+ yield
42
+ rescue RuboCop::Error => e
43
+ say_abort "[Config] #{e}"
44
+ rescue TypeError => e
45
+ say_abort "[Config] #{e}"
25
46
  end
26
47
 
27
48
  options.on("--dry", "No auto correct") do
28
49
  say "Will run rfix in {{red:read-only}} mode"
29
- Rfix.no_auto_correct!
50
+ base_config.merge!({ auto_correct: false })
51
+ end
52
+
53
+ options.on("--untracked", "Include untracked files") do
54
+ Rfix.load_untracked!
30
55
  end
31
56
 
32
57
  options.on("--list-files", "List files found by git") do
@@ -48,9 +73,6 @@ when "info"
48
73
  say "Using Git {{yellow:#{Rfix.git_version}}}"
49
74
  say "Using Ruby {{yellow:#{Rfix.ruby_version}}}"
50
75
  exit 0
51
- when "lint"
52
- Rfix.lint_mode!
53
- reference = Rfix.ref_since_push
54
76
  when "local"
55
77
  reference = Rfix.ref_since_push
56
78
  when "origin"
@@ -80,7 +102,6 @@ else
80
102
  say_error_sub "\t{{bold:rfix local}} -- {{italic:Fix changes not yet pushed to upstream branch}}"
81
103
  say_error_sub "\t{{bold:rfix info}} -- {{italic:Display runtime dependencies and their versions}}"
82
104
  say_error_sub "\t{{bold:rfix all}} -- {{italic:Fix all files in this repository}} {{warning:(not recommended)}}"
83
- say_error_sub "\t{{bold:rfix lint}} -- {{italic:Shortcut for 'local --dry --untracked'}}"
84
105
  say_error_sub "\n"
85
106
  say_error_sub "\t{{italic:Optional args: --dry --help --list-files --limit-files --config --untracked}}"
86
107
  exit 1
@@ -96,11 +117,11 @@ rescue OptionParser::MissingArgument => e
96
117
  end
97
118
 
98
119
  if path = config_path
99
- Rfix.load_config do
120
+ load_config do
100
121
  config.options_config = path
101
122
  end
102
123
  else
103
- Rfix.load_config do
124
+ load_config do
104
125
  config.for(Dir.pwd)
105
126
  end
106
127
  end
@@ -128,7 +149,7 @@ if should_list_files
128
149
  end
129
150
 
130
151
  env = RuboCop::CLI::Environment.new(
131
- Rfix.config.merge(options),
152
+ base_config.merge(options),
132
153
  config,
133
154
  paths
134
155
  )
@@ -5,22 +5,9 @@
5
5
 
6
6
  require "rfix/version"
7
7
  require "rfix/log"
8
- require "rfix/extensions/extensions"
9
- require "rfix/extensions/offense"
8
+ require "rfix/extensions"
10
9
  require "rfix/rfix"
11
10
 
12
11
  module Rfix
13
- module Ext; end
14
12
  extend self
15
13
  end
16
-
17
- RuboCop::Options.prepend(Rfix::Ext::Options)
18
- RuboCop::Runner.prepend(Rfix::Ext::Runner)
19
- RuboCop::CommentConfig.prepend(Rfix::Ext::CommentConfig)
20
- RuboCop::Cop::Offense.prepend(Rfix::Ext::Offense)
21
-
22
- # TODO: Handle cases where color can't be resolved by CLI::UI
23
- RuboCop::Formatter::SimpleTextFormatter::COLOR_FOR_SEVERITY.each do |severity, color|
24
- id = RuboCop::Cop::Severity::CODE_TABLE.invert.fetch(severity)
25
- CLI::UI::Glyph.new(id.to_s, 0x25cf, CLI::UI.resolve_color(color))
26
- end
@@ -13,7 +13,7 @@ module Rfix::Cmd
13
13
  unless status.success?
14
14
  return yield if block_given?
15
15
 
16
- say_error "[Cmd] {{italic:#{args.join(' ')}}}"
16
+ say_error "[Cmd] {{italic:#{args.join(" ")}}}"
17
17
  say_error "[Pwd] {{italic:#{Dir.pwd}}}"
18
18
  say_error "[Err] {{error:#{err.strip}}}"
19
19
 
@@ -0,0 +1,92 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rubocop"
4
+ require "rainbow"
5
+
6
+ module Rfix::Ext
7
+ module CommentConfig
8
+ # Called by RuboCop on every line to see
9
+ # if its suppose to run against it or not
10
+ def cop_enabled_at_line?(_cop, line)
11
+ Rfix.enabled?(processed_source.file_path, line) && super
12
+ end
13
+ end
14
+
15
+ module Runner
16
+ # Called _after_ @source has been 'auto fixed' by Rubocop
17
+ def check_for_infinite_loop(source, offences)
18
+ Rfix.refresh!(source); super # TODO: Before or after?
19
+ end
20
+ end
21
+
22
+ module Options
23
+ # Appends custom --args to RuboCop CLI
24
+ def define_options
25
+ super.tap do |options|
26
+ @ons.each do |args, block|
27
+ option(options, *args, &block)
28
+ end
29
+ end
30
+ end
31
+
32
+ # Helper method used by rfix to append cli --args to Rubocop
33
+ def on(*args, &block)
34
+ @ons ||= []
35
+ @ons += [[args, block]]
36
+ end
37
+ end
38
+
39
+ module Offense
40
+ def where
41
+ line.to_s + ":" + real_column.to_s
42
+ end
43
+
44
+ def info
45
+ message.split(": ", 2).last.delete("\n")
46
+ end
47
+
48
+ def msg
49
+ CLI::UI.resolve_text("{{italic:#{info}}}", truncate_to: CLI::UI::Terminal.width - 10)
50
+ end
51
+
52
+ def code
53
+ message.split(": ", 2).first
54
+ end
55
+
56
+ def star
57
+ Rainbow("⭑")
58
+ end
59
+
60
+ def cross
61
+ Rainbow("✗")
62
+ end
63
+
64
+ def check
65
+ Rainbow("✓")
66
+ end
67
+
68
+ def level
69
+ colors = {
70
+ refactor: star.lightcyan,
71
+ convention: star.lightblue,
72
+ warning: star.lightyellow,
73
+ error: cross.indianred,
74
+ fatal: cross.lightsalmon
75
+ }
76
+
77
+ colors[severity.name]
78
+ end
79
+
80
+ def icon
81
+ return check.green if corrected?
82
+ return check.lightgreen if correctable?
83
+
84
+ cross.indianred
85
+ end
86
+ end
87
+ end
88
+
89
+ RuboCop::Options.prepend(Rfix::Ext::Options)
90
+ RuboCop::Runner.prepend(Rfix::Ext::Runner)
91
+ RuboCop::CommentConfig.prepend(Rfix::Ext::CommentConfig)
92
+ RuboCop::Cop::Offense.prepend(Rfix::Ext::Offense)
@@ -30,14 +30,37 @@ module Rfix
30
30
  report_summary(files.size, offenses.count, corrected.count)
31
31
  end
32
32
 
33
+ def to_clickable(url, title)
34
+ esc = CLI::UI::ANSI::ESC
35
+ cmd = esc + "]8;;"
36
+ slash = "\x07"
37
+ cmd + "#{escape(url)}#{slash}#{escape(title)}" + cmd + slash
38
+ end
39
+
40
+ def to_path(path, title)
41
+ to_clickable("file://#{path}", title)
42
+ end
43
+
44
+ def to_url(url, title)
45
+ to_clickable(url, title)
46
+ end
47
+
48
+ def escape(str)
49
+ Shellwords.escape(str)
50
+ end
51
+
33
52
  def render_file(file, offenses)
34
53
  return if offenses.empty?
35
54
 
55
+ path = Rfix.to_relative(path: file)
56
+ url = to_url(file, path)
36
57
  offenses.each do |offense|
37
58
  out("\n\n")
59
+ clickable_path = "{{italic:#{path}:#{offense.where}}}"
60
+ clickable_code = to_url("https://www.rubydoc.info/gems/rubocop/RuboCop/Cop/#{offense.code}", offense.code)
38
61
  CLI::UI::Frame.open("#{offense.icon} #{offense.msg}", color: :reset)
39
62
  report_line(file, offense, offense.location, offense.highlighted_area)
40
- CLI::UI::Frame.close("#{offense.clickable_severity} » #{offense.clickable_path}", color: :reset)
63
+ CLI::UI::Frame.close("#{clickable_path} » {{italic:#{clickable_code}}}", color: :reset)
41
64
  end
42
65
  end
43
66
 
@@ -19,9 +19,7 @@ module Rfix::GitHelper
19
19
  "--no-renames",
20
20
  "--no-merges",
21
21
  "--first-parent",
22
- "--find-renames",
23
- "--find-copies",
24
- "--diff-filter=AMCR",
22
+ "--diff-filter=AM",
25
23
  "-U0",
26
24
  "--no-color",
27
25
  "-p"
@@ -13,7 +13,7 @@ module Rfix::Log
13
13
  end
14
14
 
15
15
  def say_error_sub(message)
16
- CLI::UI.puts(message.to_s)
16
+ CLI::UI.puts("#{message}")
17
17
  end
18
18
 
19
19
  def say_debug(message)
@@ -13,36 +13,6 @@ module Rfix
13
13
  include GitHelper
14
14
  include Log
15
15
 
16
- def config
17
- @config
18
- end
19
-
20
- def set_fail_level(lint)
21
- if if lint
22
- else
23
- @config[:fail_level] = :warning
24
- end
25
- end
26
- end
27
-
28
- def no_auto_correct!
29
- @config[:auto_correct] = false
30
- end
31
-
32
- def load_config
33
- yield
34
- rescue RuboCop::Error => e
35
- say_abort "[Config] #{e}"
36
- rescue TypeError => e
37
- say_abort "[Config] #{e}"
38
- end
39
-
40
- def lint_mode!
41
- @config[:auto_correct] = false
42
- @config[:fail_level] = :warning if old?
43
- load_untracked!
44
- end
45
-
46
16
  def git_version
47
17
  cmd("git --version").last.split(/\s+/, 3).last
48
18
  end
@@ -66,14 +36,6 @@ module Rfix
66
36
  def init!
67
37
  @files ||= {}
68
38
  @global_enable = false
69
- @config = {
70
- color: true,
71
- force_exclusion: true,
72
- auto_correct: true,
73
- formatters: ["Rfix::Formatter"]
74
- }
75
-
76
- @config[:fail_level] = :autocorrect if old?
77
39
  end
78
40
 
79
41
  def files
@@ -138,12 +100,6 @@ module Rfix
138
100
 
139
101
  private
140
102
 
141
- def old?
142
- # For version 0.80.x .. 0.83.x:
143
- # Otherwise it will exit with status code = 1
144
- (0.80..0.83).include?(RuboCop::Version::STRING.to_f)
145
- end
146
-
147
103
  def get_file(path, &block)
148
104
  if file = @files[path]
149
105
  block.call(file)
@@ -19,16 +19,16 @@ Gem::Specification.new do |spec|
19
19
 
20
20
  spec.summary = "RuboCop CLI that only complains about your latest changes"
21
21
  spec.description = <<~TEXT
22
- #{spec.summary}
23
- Uses 'git diff' to determine what changes were made then runs RuboCop against them
22
+ #{spec.summary}
23
+ Uses 'git diff' to determine what changes were made then runs RuboCop against them
24
24
 
25
- $ rfix branch <branch> -- Fix changes made between HEAD and <branch>
26
- $ rfix origin -- Fix changes made between HEAD and origin branch
27
- $ rfix local -- Fix changes not yet pushed to upstream branch
28
- $ rfix info -- Display runtime dependencies and their versions
29
- $ rfix all -- Fix all files in this repository (not recommended)
25
+ $ rfix branch <branch> -- Fix changes made between HEAD and <branch>
26
+ $ rfix origin -- Fix changes made between HEAD and origin branch
27
+ $ rfix local -- Fix changes not yet pushed to upstream branch
28
+ $ rfix info -- Display runtime dependencies and their versions
29
+ $ rfix all -- Fix all files in this repository (not recommended)
30
30
 
31
- Optional args: --dry --help --list-files --limit-files --config --untracked
31
+ Optional args: --dry --help --list-files --limit-files --config --untracked
32
32
  TEXT
33
33
  spec.homepage = "https://github.com/oleander/rfix-rb"
34
34
  spec.license = "MIT"
@@ -48,8 +48,6 @@ Gem::Specification.new do |spec|
48
48
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
49
49
  spec.require_paths = ["lib", "vendor/cli-ui/lib"]
50
50
 
51
- spec.requirements << "git, v2.0+"
52
-
53
51
  spec.add_runtime_dependency "rainbow", "~> 3.0"
54
52
  spec.add_runtime_dependency "rouge", "~> 3.20"
55
53
  spec.add_runtime_dependency "rubocop", "~> 0.80"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rfix
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.7.pre.68
4
+ version: 1.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Linus Oleander
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-06-21 00:00:00.000000000 Z
11
+ date: 2020-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rainbow
@@ -52,17 +52,14 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0.80'
55
- description: |2
56
- RuboCop CLI that only complains about your latest changes
57
- Uses 'git diff' to determine what changes were made then runs RuboCop against them
58
-
59
- $ rfix branch <branch> -- Fix changes made between HEAD and <branch>
60
- $ rfix origin -- Fix changes made between HEAD and origin branch
61
- $ rfix local -- Fix changes not yet pushed to upstream branch
62
- $ rfix info -- Display runtime dependencies and their versions
63
- $ rfix all -- Fix all files in this repository (not recommended)
64
-
65
- Optional args: --dry --help --list-files --limit-files --config --untracked
55
+ description: "RuboCop CLI that only complains about your latest changes\nUses 'git
56
+ diff' to determine what changes were made then runs RuboCop against them\n\n\t$
57
+ rfix branch <branch> -- Fix changes made between HEAD and <branch>\n\t$ rfix origin
58
+ \ -- Fix changes made between HEAD and origin branch\n\t$ rfix local --
59
+ Fix changes not yet pushed to upstream branch\n\t$ rfix info -- Display
60
+ runtime dependencies and their versions\n\t$ rfix all -- Fix all files
61
+ in this repository (not recommended)\n\nOptional args: --dry --help --list-files
62
+ --limit-files --config --untracked\n"
66
63
  email:
67
64
  - linus@oleander.nu
68
65
  executables:
@@ -99,8 +96,7 @@ files:
99
96
  - exe/rfix
100
97
  - lib/rfix.rb
101
98
  - lib/rfix/cmd.rb
102
- - lib/rfix/extensions/extensions.rb
103
- - lib/rfix/extensions/offense.rb
99
+ - lib/rfix/extensions.rb
104
100
  - lib/rfix/formatter.rb
105
101
  - lib/rfix/git_file.rb
106
102
  - lib/rfix/git_helper.rb
@@ -109,7 +105,6 @@ files:
109
105
  - lib/rfix/tracked_file.rb
110
106
  - lib/rfix/untracked_file.rb
111
107
  - lib/rfix/version.rb
112
- - resources/ps.png
113
108
  - rfix.gemspec
114
109
  - vendor/cli-ui/lib/cli/ui.rb
115
110
  - vendor/cli-ui/lib/cli/ui/ansi.rb
@@ -141,7 +136,7 @@ licenses:
141
136
  - MIT
142
137
  metadata:
143
138
  homepage_uri: https://github.com/oleander/rfix-rb
144
- post_install_message:
139
+ post_install_message:
145
140
  rdoc_options: []
146
141
  require_paths:
147
142
  - lib
@@ -153,13 +148,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
153
148
  version: 2.5.0
154
149
  required_rubygems_version: !ruby/object:Gem::Requirement
155
150
  requirements:
156
- - - ">"
151
+ - - ">="
157
152
  - !ruby/object:Gem::Version
158
- version: 1.3.1
159
- requirements:
160
- - git, v2.0+
161
- rubygems_version: 3.0.3
162
- signing_key:
153
+ version: '0'
154
+ requirements: []
155
+ rubygems_version: 3.1.4
156
+ signing_key:
163
157
  specification_version: 4
164
158
  summary: RuboCop CLI that only complains about your latest changes
165
159
  test_files: []
@@ -1,40 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "rubocop"
4
- require "rainbow"
5
-
6
- module Rfix::Ext
7
- module CommentConfig
8
- # Called by RuboCop on every line to see
9
- # if its suppose to run against it or not
10
- def cop_enabled_at_line?(_cop, line)
11
- Rfix.enabled?(processed_source.file_path, line) && super
12
- end
13
- end
14
-
15
- module Runner
16
- # Called _after_ @source has been 'auto fixed' by Rubocop
17
- def check_for_infinite_loop(source, offences)
18
- # rubocop:disable Style/Semicolon
19
- Rfix.refresh!(source); super
20
- # rubocop:enable Style/Semicolon
21
- end
22
- end
23
-
24
- module Options
25
- # Appends custom --args to RuboCop CLI
26
- def define_options
27
- super.tap do |options|
28
- @ons.each do |args, block|
29
- option(options, *args, &block)
30
- end
31
- end
32
- end
33
-
34
- # Helper method used by rfix to append cli --args to Rubocop
35
- def on(*args, &block)
36
- @ons ||= []
37
- @ons += [[args, block]]
38
- end
39
- end
40
- end
@@ -1,77 +0,0 @@
1
- module Rfix::Ext
2
- module Offense
3
- def where
4
- line.to_s + ":" + real_column.to_s
5
- end
6
-
7
- def info
8
- message.split(": ", 2).last.delete("\n")
9
- end
10
-
11
- def msg
12
- CLI::UI.resolve_text("{{italic:#{info}}}", truncate_to: CLI::UI::Terminal.width - 10)
13
- end
14
-
15
- def code
16
- message.split(": ", 2).first
17
- end
18
-
19
- def star
20
- Rainbow("⭑")
21
- end
22
-
23
- def cross
24
- Rainbow("✗").red
25
- end
26
-
27
- def check
28
- Rainbow("✓").green
29
- end
30
-
31
- def circle
32
- Rainbow("⍟")
33
- end
34
-
35
- def relative_path
36
- Rfix.to_relative(path: location.source_buffer.name)
37
- end
38
-
39
- def clickable_path
40
- "{{italic:#{relative_path}:#{where}}}"
41
- end
42
-
43
- def clickable_plain_severity
44
- to_url("https://www.rubydoc.info/gems/rubocop/RuboCop/Cop/#{code}", code)
45
- end
46
-
47
- def clickable_severity
48
- "{{#{severity.code}}} {{italic:#{clickable_plain_severity}}}"
49
- end
50
-
51
- def icon
52
- return check.green if corrected?
53
- return star.yellow if correctable?
54
-
55
- cross.red
56
- end
57
-
58
- def to_clickable(url, title)
59
- esc = CLI::UI::ANSI::ESC
60
- cmd = esc + "]8;;"
61
- slash = "\x07"
62
- cmd + "#{escape(url)}#{slash}#{escape(title)}" + cmd + slash
63
- end
64
-
65
- def to_path(path, title)
66
- to_clickable("file://#{path}", title)
67
- end
68
-
69
- def to_url(url, title)
70
- to_clickable(url, title)
71
- end
72
-
73
- def escape(str)
74
- Shellwords.escape(str)
75
- end
76
- end
77
- end
Binary file