rubocop-infl 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/.gitignore +10 -0
- data/.rspec +3 -0
- data/.rubocop.yml +2 -0
- data/.travis.yml +5 -0
- data/CHANGELOG.md +9 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +46 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/config/default.yml +7 -0
- data/lib/rubocop-infl.rb +14 -0
- data/lib/rubocop/cop/infl/soft_line_length.rb +80 -0
- data/lib/rubocop/infl.rb +11 -0
- data/lib/rubocop/infl/inject.rb +14 -0
- data/lib/rubocop/infl/version.rb +5 -0
- data/rubocop-infl.gemspec +30 -0
- metadata +132 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d1f2bad13d346b66bb105969eda469c6fc45a682
|
4
|
+
data.tar.gz: ed0e5074b19994f275f251a06374ccfb0e134eb2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4ee9fc11216a22868cab9393e99482493ead824c0693eb70c239ae7b72e00faf9bbb37310ee77d2fe099f17b8a5c0c23a00b0ed20792a88af15fce8a71241321
|
7
|
+
data.tar.gz: e7742f6da0d59f149af2f80d3f4071c779a11aa2e1aa770adaeb357fa19e41296450ccdeec52d2516ebb9151df858386e9da2ea57582a461a4508d074b9b0720
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016-2017 Influitive Corp., Mike Stok
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# Rubocop::Infl
|
2
|
+
|
3
|
+
This gem contains Influitive specific rubocop cops. To use them you can do this
|
4
|
+
in your `Gemfile` for a project:
|
5
|
+
|
6
|
+
group :development to
|
7
|
+
gem 'rubocop', require: false
|
8
|
+
gem 'rubocop-infl', require: false
|
9
|
+
end
|
10
|
+
|
11
|
+
And add this to your `.rubocop.yml` for the project:
|
12
|
+
|
13
|
+
require: "rubocop-infl"
|
14
|
+
|
15
|
+
## Infl/SoftLineLength
|
16
|
+
|
17
|
+
It is considered good style to limit the length of lines in Ruby source code,
|
18
|
+
and we have found that *sometimes* there are lines which are a little longer
|
19
|
+
than our conventional limit and breaking up made the code less readable and
|
20
|
+
"greppable". This Cop attempts to help with that situation by allowing a file
|
21
|
+
to have up to a certain percentage of the lines be longer than our "usual"
|
22
|
+
limit.
|
23
|
+
|
24
|
+
Metrics/LineLength:
|
25
|
+
Enabled: false
|
26
|
+
|
27
|
+
Infl/SoftLineLength:
|
28
|
+
Enabled: true
|
29
|
+
SoftLimit: 80
|
30
|
+
HardLimit: 120
|
31
|
+
AllowedLongLinePercentage: 2
|
32
|
+
|
33
|
+
This would complain about *any* lines which were longer than 120 characters,
|
34
|
+
and allow up to 2% of lines in a file to be longer than 80 characters
|
35
|
+
before starting to complain about the lines longer that 80 characters.
|
36
|
+
|
37
|
+
# Inspiration
|
38
|
+
|
39
|
+
Shamelessly based on https://github.com/backus/rubocop-rspec
|
40
|
+
|
41
|
+
http://rubocop.readthedocs.io/en/latest/extensions/#custom-cop has more
|
42
|
+
information on custom cops.
|
43
|
+
|
44
|
+
# License
|
45
|
+
|
46
|
+
This is licensed under the [MIT License](./LICENSE.txt)
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'rubocop/infl'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/config/default.yml
ADDED
data/lib/rubocop-infl.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# rubocop:disable Style/FileName
|
2
|
+
|
3
|
+
require 'pathname'
|
4
|
+
require 'yaml'
|
5
|
+
|
6
|
+
require 'rubocop'
|
7
|
+
|
8
|
+
require 'rubocop/infl'
|
9
|
+
require 'rubocop/infl/version'
|
10
|
+
require 'rubocop/infl/inject'
|
11
|
+
|
12
|
+
RuboCop::Infl::Inject.defaults!
|
13
|
+
|
14
|
+
require 'rubocop/cop/infl/soft_line_length'
|
@@ -0,0 +1,80 @@
|
|
1
|
+
module RuboCop
|
2
|
+
module Cop
|
3
|
+
module Infl
|
4
|
+
# Checks forgivingly for line lengths
|
5
|
+
class SoftLineLength < Cop
|
6
|
+
HARD_MSG = 'Line exceeds hard length limit. [%d/%d]'.freeze
|
7
|
+
SOFT_MSG = 'Line exceeds soft length limit. [%d/%d]'.freeze
|
8
|
+
|
9
|
+
include RuboCop::Cop::ConfigurableEnforcedStyle
|
10
|
+
|
11
|
+
def investigate(processed_source)
|
12
|
+
stats = calculate_stats(processed_source)
|
13
|
+
soft_credit =
|
14
|
+
(stats.size * soft_allowance_percent_of_lines / 100.0).round
|
15
|
+
|
16
|
+
stats.each do |check, index, length|
|
17
|
+
soft_credit = report(soft_credit, check, index, length)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def calculate_stats(processed_source)
|
24
|
+
processed_source
|
25
|
+
.lines
|
26
|
+
.each_with_index
|
27
|
+
.map { |line, index| check_line(line, index) }
|
28
|
+
.compact
|
29
|
+
end
|
30
|
+
|
31
|
+
def check_line(line, index)
|
32
|
+
case line.length
|
33
|
+
when 0 then nil
|
34
|
+
when ->(l) { l <= soft_limit } then [:ok, nil, nil]
|
35
|
+
when ->(l) { l <= hard_limit } then [:soft, index, line.length]
|
36
|
+
else [:hard, index, line.length]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def report(soft_credit, check, index, length)
|
41
|
+
case check
|
42
|
+
when :soft
|
43
|
+
soft_credit -= 1
|
44
|
+
soft_offense(processed_source, index, length) if soft_credit < 0
|
45
|
+
when :hard
|
46
|
+
hard_offense(processed_source, index, length)
|
47
|
+
end
|
48
|
+
|
49
|
+
soft_credit
|
50
|
+
end
|
51
|
+
|
52
|
+
def soft_offense(processed_source, index, length)
|
53
|
+
offense(processed_source, SOFT_MSG, index, length, soft_limit)
|
54
|
+
end
|
55
|
+
|
56
|
+
def hard_offense(processed_source, index, length)
|
57
|
+
offense(processed_source, HARD_MSG, index, length, hard_limit)
|
58
|
+
end
|
59
|
+
|
60
|
+
def offense(processed_source, template, index, length, limit)
|
61
|
+
loc = source_range(processed_source.buffer, index + 1, 0...length)
|
62
|
+
msg = format(template, length, limit)
|
63
|
+
add_offense(nil, loc, msg)
|
64
|
+
end
|
65
|
+
|
66
|
+
def soft_limit
|
67
|
+
cop_config['SoftLimit']
|
68
|
+
end
|
69
|
+
|
70
|
+
def hard_limit
|
71
|
+
cop_config['HardLimit']
|
72
|
+
end
|
73
|
+
|
74
|
+
def soft_allowance_percent_of_lines
|
75
|
+
cop_config['AllowedLongLinePercentage']
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
data/lib/rubocop/infl.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Infl # rubocop:disable Style/Documentation
|
5
|
+
PROJECT_ROOT = Pathname.new(__dir__).parent.parent.expand_path.freeze
|
6
|
+
CONFIG_DEFAULT = PROJECT_ROOT.join('config', 'default.yml').freeze
|
7
|
+
CONFIG = YAML.safe_load(CONFIG_DEFAULT.read).freeze
|
8
|
+
|
9
|
+
private_constant(:CONFIG_DEFAULT, :PROJECT_ROOT)
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module RuboCop
|
2
|
+
module Infl
|
3
|
+
module Inject # rubocop:disable Style/Documentation
|
4
|
+
def self.defaults!
|
5
|
+
path = CONFIG_DEFAULT.to_s
|
6
|
+
hash = ConfigLoader.send(:load_yaml_configuration, path)
|
7
|
+
config = Config.new(hash, path)
|
8
|
+
puts "configuration from #{path}" if ConfigLoader.debug?
|
9
|
+
config = ConfigLoader.merge_with_default(config, path)
|
10
|
+
ConfigLoader.instance_variable_set(:@default_configuration, config)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rubocop/infl/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'rubocop-infl'
|
8
|
+
spec.version = Rubocop::Infl::VERSION
|
9
|
+
spec.authors = ['Mike Stok']
|
10
|
+
spec.email = ['mike.stok@influitive.com']
|
11
|
+
|
12
|
+
spec.summary = 'A package of Influitive cop(s) for Rubocop.'
|
13
|
+
spec.homepage = 'https://github.com/influitive/rubocop-infl'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
spec.bindir = 'exe'
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ['lib']
|
22
|
+
|
23
|
+
spec.add_runtime_dependency 'rubocop', '>= 0.37.1'
|
24
|
+
|
25
|
+
spec.add_development_dependency 'bundler', '~> 1.13'
|
26
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
27
|
+
spec.add_development_dependency 'rspec', '~> 3.5'
|
28
|
+
|
29
|
+
spec.add_development_dependency 'pry'
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rubocop-infl
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mike Stok
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-02-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rubocop
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.37.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.37.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.13'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.13'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.5'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.5'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description:
|
84
|
+
email:
|
85
|
+
- mike.stok@influitive.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".rubocop.yml"
|
93
|
+
- ".travis.yml"
|
94
|
+
- CHANGELOG.md
|
95
|
+
- Gemfile
|
96
|
+
- LICENSE.txt
|
97
|
+
- README.md
|
98
|
+
- Rakefile
|
99
|
+
- bin/console
|
100
|
+
- bin/setup
|
101
|
+
- config/default.yml
|
102
|
+
- lib/rubocop-infl.rb
|
103
|
+
- lib/rubocop/cop/infl/soft_line_length.rb
|
104
|
+
- lib/rubocop/infl.rb
|
105
|
+
- lib/rubocop/infl/inject.rb
|
106
|
+
- lib/rubocop/infl/version.rb
|
107
|
+
- rubocop-infl.gemspec
|
108
|
+
homepage: https://github.com/influitive/rubocop-infl
|
109
|
+
licenses:
|
110
|
+
- MIT
|
111
|
+
metadata: {}
|
112
|
+
post_install_message:
|
113
|
+
rdoc_options: []
|
114
|
+
require_paths:
|
115
|
+
- lib
|
116
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
requirements: []
|
127
|
+
rubyforge_project:
|
128
|
+
rubygems_version: 2.6.8
|
129
|
+
signing_key:
|
130
|
+
specification_version: 4
|
131
|
+
summary: A package of Influitive cop(s) for Rubocop.
|
132
|
+
test_files: []
|