standard 0.0.4

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of standard might be problematic. Click here for more details.

checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e5157d87d7356624fa54b57020895c05312e8dfcae7ba7b81335a3a397a866ba
4
+ data.tar.gz: 0bd2df03a127af1ea8b2fde8387b8809bf464f702da2816ec19bf5678d02bcd0
5
+ SHA512:
6
+ metadata.gz: 60d2d3031e7b2d5c422c5f192d91fa4762ce524872539f45893f9de2f464a0df0a063c40a3f2a5b81998b7c4e08134d6af06385bb05afdcb9dad274933eac1e3
7
+ data.tar.gz: 7d0235ee1bae5ad7af9324218d55e302c2e8ec9296a87e5567c4486c300bb4f7783792cc13d625ea1c2dbdf9a5c2dc7afd1bbfff0bec68587115ee14bca6f086
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,40 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ standard (0.0.4)
5
+ rubocop (>= 0.60)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.4.0)
11
+ jaro_winkler (1.5.1)
12
+ minitest (5.11.3)
13
+ parallel (1.12.1)
14
+ parser (2.5.3.0)
15
+ ast (~> 2.4.0)
16
+ powerpack (0.1.2)
17
+ rainbow (3.0.0)
18
+ rake (10.5.0)
19
+ rubocop (0.60.0)
20
+ jaro_winkler (~> 1.5.1)
21
+ parallel (~> 1.10)
22
+ parser (>= 2.5, != 2.5.1.1)
23
+ powerpack (~> 0.1)
24
+ rainbow (>= 2.2.2, < 4.0)
25
+ ruby-progressbar (~> 1.7)
26
+ unicode-display_width (~> 1.4.0)
27
+ ruby-progressbar (1.10.0)
28
+ unicode-display_width (1.4.0)
29
+
30
+ PLATFORMS
31
+ ruby
32
+
33
+ DEPENDENCIES
34
+ bundler (~> 1.17)
35
+ minitest (~> 5.0)
36
+ rake (~> 10.0)
37
+ standard!
38
+
39
+ BUNDLED WITH
40
+ 1.17.1
data/README.md ADDED
@@ -0,0 +1,253 @@
1
+ ## Standard - Ruby style guide, linter, and formatter
2
+
3
+ This gem is a spiritual port of [StandardJS](https://standardjs.com) and aims
4
+ to save you (and others!) time in the same three ways:
5
+
6
+ * **No configuration.** The easiest way to enforce consistent style in your
7
+ project. Just drop it in.
8
+ * **Automatically format code.** Just run `standard --fix` and say goodbye to
9
+ messy or inconsistent code.
10
+ * **Catch style issues & programmer errors early.** Save precious code review
11
+ time by eliminating back-and-forth between reviewer & contributor.
12
+
13
+ No decisions to make. It just works.
14
+
15
+ Install by adding it to your Gemfile:
16
+
17
+ ```ruby
18
+ gem "standard", :require => false
19
+ ```
20
+
21
+ And running `bundle install`.
22
+
23
+ Run StandardRB from the command line with:
24
+
25
+ ```ruby
26
+ $ bundle exec standard
27
+ ```
28
+
29
+ And if you'd like, StandardRB can autocorrect your code by tacking on a `--fix`
30
+ flag.
31
+
32
+ ## StandardRB — The Rules
33
+
34
+ - **2 spaces** – for indentation
35
+ - **Double quotes for string literals** - because pre-committing to whether
36
+ you'll need interpolation in a string slows people down
37
+ - **Hashrockets** - Hashrockets.
38
+ - **Semantic blocks** - `{`/`}` for functional blocks that return a value, and
39
+ `do`/`end` for procedural blocks that have side effects. More
40
+ [here](http://www.virtuouscode.com/2011/07/26/the-procedurefunction-block-convention-in-ruby/)
41
+ and [here](https://github.com/rubocop-hq/ruby-style-guide/issues/162)
42
+ - **Trailing dots on multi-line method chains** - chosen because it makes
43
+ copying lines into a REPL easier
44
+ - **And a good deal more**
45
+
46
+ If you're familiar with [RuboCop](https://github.com/rubocop-hq/rubocop), you
47
+ can look at StandardRB's current base configuration in
48
+ [config/base.yml](/config/base.yml).
49
+
50
+ **[NOTE: until StandardRB hits 1.0.0, we consider this configuration to be a
51
+ non-final work in progress and we encourage you to submit your opinions (and
52
+ reasoned arguments) for the addition, removal, or change to a rule by [opening
53
+ an issue](https://github.com/testdouble/standard/issues/new). If you start using
54
+ StandardRB, don't be shocked if things change a bit!]**
55
+
56
+ ## Usage
57
+
58
+ Once you've installed `standard`, you should be able to use the `standard`
59
+ program. The simplest use case would be checking the style of all Ruby
60
+ files in the current working directory:
61
+
62
+ ```bash
63
+ $ bundle exec standard
64
+ standard: Use Ruby Standard Style (https://github.com/testdouble/standard)
65
+ standard: Run `standard --fix` to automatically fix some problems.
66
+ /Users/code/cli.rb:31:23: Style/Semicolon: Do not use semicolons to terminate expressions.
67
+ ```
68
+
69
+ You can optionally pass in a directory (or directories) using the glob pattern. Be
70
+ sure to quote paths containing glob patterns so that they are expanded by
71
+ `standard` instead of your shell:
72
+
73
+ ```bash
74
+ $ bundle exec standard "lib/**/*.rb" test
75
+ ```
76
+
77
+ **Note:** by default `standard` will look for all `*.rb` files (and some other
78
+ files typically associated with Ruby like `*.gemspec` and `Gemfile`)
79
+
80
+ ## What you might do if you're clever
81
+
82
+ If you want or need to configure StandardRB, there are a _handful_ of options
83
+ are available creating a `.standard.yml` file in the root of your project.
84
+
85
+ Here's an example yaml file with every option set:
86
+
87
+ ```yaml
88
+ fix: true
89
+ parallel: true
90
+ format: progress
91
+
92
+ ignore:
93
+ - 'db/schema.rb'
94
+ - 'vendor/bundle/**/*'
95
+ - 'test/**/*':
96
+ - Style/BlockDelimiters
97
+ ```
98
+
99
+ ## What you might do if you're REALLY clever
100
+
101
+ Because StandardRB is essentially a wrapper on top of
102
+ [RuboCop](https://github.com/rubocop-hq/rubocop), it will actually forward the
103
+ vast majority of CLI and ENV arguments forward to RuboCop.
104
+
105
+ You can see a list of
106
+ [RuboCop](https://docs.rubocop.org/en/latest/basic_usage/#other-useful-command-line-flags)'s
107
+ CLI flags here.
108
+
109
+ ## Why should I use Ruby Standard Style?
110
+
111
+ (This section will [look
112
+ familiar](https://github.com/standard/standard#why-should-i-use-javascript-standard-style)
113
+ if you've used StandardJS.)
114
+
115
+ The beauty of Ruby Standard Style is that it's simple. No one wants to
116
+ maintain multiple hundred-line style configuration files for every module/project
117
+ they work on. Enough of this madness!
118
+
119
+ This module saves you (and others!) time in three ways:
120
+
121
+ - **No configuration.** The easiest way to enforce consistent style in your
122
+ project. Just drop it in.
123
+ - **Automatically format code.** Just run `standard --fix` and say goodbye to
124
+ messy or inconsistent code.
125
+ - **Catch style issues & programmer errors early.** Save precious code review
126
+ time by eliminating back-and-forth between reviewer & contributor.
127
+
128
+ Adopting `standard` style means ranking the importance of code clarity and
129
+ community conventions higher than personal style. This might not make sense for
130
+ 100% of projects and development cultures, however open source can be a hostile
131
+ place for newbies. Setting up clear, automated contributor expectations makes a
132
+ project healthier.
133
+
134
+ ## Who uses Ruby Standard Style?
135
+
136
+ (This section will not [look very
137
+ familiar](https://github.com/standard/standard#who-uses-javascript-standard-style)
138
+ if you've used StandardJS.)
139
+
140
+ Almost nobody! (Yet!)
141
+
142
+ ## Is there a readme badge?
143
+
144
+ Yes! If you use `standard` in your project, you can include one of these badges
145
+ in your readme to let people know that your code is using the standard style.
146
+
147
+
148
+ [![Ruby Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://github.com/testdouble/standard)
149
+
150
+ ```md
151
+ [![Ruby Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://github.com/testdouble/standard)
152
+ ```
153
+
154
+ ## I disagree with rule X, can you change it?
155
+
156
+ **[NOTE: until StandardRB hits 1.0.0, the answer is yes! It just requires
157
+ [opening an issue](https://github.com/testdouble/standard/issues/new) and
158
+ convincing [@searls](https://twitter.com/searls) (the BDFNow) to make the
159
+ change.]**
160
+
161
+ No. The whole point of `standard` is to save you time by avoiding
162
+ [bikeshedding](https://www.freebsd.org/doc/en/books/faq/misc.html#bikeshed-painting)
163
+ about code style. There are lots of debates online about tabs vs. spaces, etc.
164
+ that will never be resolved. These debates just distract from getting stuff
165
+ done. At the end of the day you have to 'just pick something', and that's the
166
+ whole philosophy of `standard` -- its a bunch of sensible 'just pick something'
167
+ opinions. Hopefully, users see the value in that over defending their own
168
+ opinions.
169
+
170
+ Pro tip: Just use `standard` and move on. There are actual real problems that
171
+ you could spend your time solving! :P
172
+
173
+ ## Is there an automatic formatter?
174
+
175
+ Yes! You can use `standard --fix` to fix most issues automatically.
176
+
177
+ `standard --fix` is built into `standard` for maximum convenience. Most problems
178
+ are fixable, but some errors (like forgetting to handle errors) must be fixed
179
+ manually.
180
+
181
+ To save you time, `standard` outputs the message "`Run standard --fix to
182
+ automatically fix some problems`" when it detects problems that can be fixed
183
+ automatically.
184
+
185
+ ## How do I ignore files?
186
+
187
+ Sometimes you need to ignore additional folders or specific minified files. To
188
+ do that, add a `.standard.yml` file to the root of your project and specify a
189
+ list of files and globs that should be excluded:
190
+
191
+ ```yaml
192
+ ignore:
193
+ - 'db/schema.rb'
194
+ - 'vendor/bundle/**/*'
195
+ ```
196
+
197
+ ## How do I hide a certain warning?
198
+
199
+ In rare cases, you'll need to break a rule and hide the warning generated by
200
+ `standard`.
201
+
202
+ Ruby Standard Style uses [RuboCop](https://github.com/rubocop-hq/rubocop)
203
+ under-the-hood and you can hide warnings as you normally would if you used
204
+ RuboCop directly.
205
+
206
+ To ignore only certain rules from certain globs (not recommended, but maybe your
207
+ test suite uses a non-standardable DSL, you can specify an array of RuboCop
208
+ rules to ignore for a particular glob:
209
+
210
+ ```yaml
211
+ ignore:
212
+ - 'test/**/*':
213
+ - Style/BlockDelimiters
214
+ ```
215
+
216
+ You can also use special comments to disable all or certain rules within your
217
+ source code. See [RuboCop's
218
+ docs](https://docs.rubocop.org/en/latest/configuration/#disabling-cops-within-source-code)
219
+ for details.
220
+
221
+ ## How do I change the output?
222
+
223
+ StandardRB's built-in formatter is intentionally minimal, printing only unfixed
224
+ failures or (if successful) a "Done" message. If you'd like to use a different
225
+ formatter, you can specify any of RuboCopy's built-in formatters or write your
226
+ own.
227
+
228
+ For example, if you'd like to see colorful progress dots, you can either run
229
+ standard with:
230
+
231
+ ```
232
+ $ bundle exec standard --format progress
233
+ Inspecting 15 files
234
+ ...............
235
+
236
+ 15 files inspected, no offenses detected
237
+ ✨ Done in 0.42s.
238
+ ```
239
+
240
+ Or, in your project's `.standard.yml` file, specify:
241
+
242
+ ```yaml
243
+ format: progress
244
+ ```
245
+
246
+ Refer to RuboCop's [documentation on
247
+ formatters](https://rubocop.readthedocs.io/en/latest/formatters/) for more
248
+ information.
249
+
250
+ ## License
251
+
252
+ [MIT](LICENSE). Copyright (c) [Test Double, LLC](https://testdouble.com).
253
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "standard"
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(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/config/base.yml ADDED
@@ -0,0 +1,142 @@
1
+ Bundler/OrderedGems:
2
+ Enabled: false
3
+
4
+ Layout/AlignParameters:
5
+ EnforcedStyle: with_fixed_indentation
6
+
7
+ Layout/AlignHash:
8
+ EnforcedLastArgumentHashStyle: always_ignore
9
+
10
+ # Disabled because IndentOneStep can't be configured for one-liner cases. See:
11
+ # https://github.com/rubocop-hq/rubocop/issues/6447
12
+ Layout/CaseIndentation:
13
+ Enabled: false
14
+
15
+ Layout/DotPosition:
16
+ EnforcedStyle: trailing
17
+
18
+ Layout/EmptyLineAfterGuardClause:
19
+ Enabled: false
20
+
21
+ Layout/EndAlignment:
22
+ EnforcedStyleAlignWith: variable
23
+
24
+ Layout/FirstParameterIndentation:
25
+ EnforcedStyle: consistent
26
+
27
+ Layout/IndentHash:
28
+ EnforcedStyle: consistent
29
+
30
+ Layout/IndentArray:
31
+ EnforcedStyle: consistent
32
+
33
+ Layout/MultilineMethodCallIndentation:
34
+ EnforcedStyle: indented
35
+
36
+ # Disabled without this:
37
+ # http://github.com/rubocop-hq/rubocop/issues/6446
38
+ Layout/SpaceInsideBlockBraces:
39
+ Enabled: false
40
+
41
+ Layout/SpaceInsideHashLiteralBraces:
42
+ EnforcedStyle: no_space
43
+
44
+ Lint/AssignmentInCondition:
45
+ Enabled: true
46
+
47
+ Metrics/AbcSize:
48
+ Enabled: false
49
+
50
+ Metrics/BlockLength:
51
+ Enabled: false
52
+
53
+ Metrics/ClassLength:
54
+ Enabled: false
55
+
56
+ Metrics/LineLength:
57
+ Enabled: false
58
+
59
+ Metrics/MethodLength:
60
+ Enabled: false
61
+
62
+ Metrics/ModuleLength:
63
+ Enabled: false
64
+
65
+ Metrics/ParameterLists:
66
+ Enabled: false
67
+
68
+ Naming/UncommunicativeMethodParamName:
69
+ Enabled: false
70
+
71
+ Naming/VariableNumber:
72
+ Enabled: false
73
+
74
+ Style/BlockDelimiters:
75
+ EnforcedStyle: semantic
76
+
77
+ Style/ClassAndModuleChildren:
78
+ Enabled: false
79
+
80
+ Style/Documentation:
81
+ Enabled: false
82
+
83
+ Style/DoubleNegation:
84
+ Enabled: false
85
+
86
+ Style/EmptyMethod:
87
+ EnforcedStyle: expanded
88
+
89
+ Style/ExpandPathArguments:
90
+ Enabled: false
91
+
92
+ Style/FormatStringToken:
93
+ Enabled: false
94
+
95
+ Style/FrozenStringLiteralComment:
96
+ EnforcedStyle: never
97
+
98
+ Style/GuardClause:
99
+ Enabled: false
100
+
101
+ Style/HashSyntax:
102
+ EnforcedStyle: hash_rockets
103
+
104
+ Style/IfUnlessModifier:
105
+ Enabled: false
106
+
107
+ Style/MultilineBlockChain:
108
+ Enabled: false
109
+
110
+ Style/MutableConstant:
111
+ Enabled: false
112
+
113
+ Style/NumericPredicate:
114
+ Enabled: false
115
+
116
+ Style/RescueStandardError:
117
+ EnforcedStyle: implicit
118
+
119
+ Style/StringLiterals:
120
+ EnforcedStyle: double_quotes
121
+
122
+ Style/StringLiteralsInInterpolation:
123
+ EnforcedStyle: double_quotes
124
+
125
+ Style/StructInheritance:
126
+ Enabled: false
127
+
128
+ Style/SymbolArray:
129
+ Enabled: false
130
+
131
+ Style/TrailingCommaInArguments:
132
+ Enabled: false
133
+
134
+ Style/TrailingCommaInArrayLiteral:
135
+ EnforcedStyleForMultiline: consistent_comma
136
+
137
+ Style/TrailingCommaInHashLiteral:
138
+ EnforcedStyleForMultiline: consistent_comma
139
+
140
+ Style/WordArray:
141
+ Enabled: false
142
+
data/exe/standard ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift("#{__dir__}/../lib")
4
+
5
+ require "standard"
6
+
7
+ exit Standard::Cli.new.run
data/exe/standardrb ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift("#{__dir__}/../lib")
4
+
5
+ require "standard"
6
+
7
+ exit Standard::Cli.new.run
@@ -0,0 +1,42 @@
1
+ require "rubocop"
2
+ require_relative "config"
3
+ require_relative "timer"
4
+
5
+ module Standard
6
+ class Cli
7
+ SUCCESS_STATUS_CODE = 0
8
+ FAILURE_STATUS_CODE = 1
9
+
10
+ def initialize
11
+ @config = Config.new(ARGV)
12
+ @timer = Timer.new
13
+ end
14
+
15
+ def run
16
+ rubocop_config = @config.to_rubocop
17
+ runner = RuboCop::Runner.new(
18
+ rubocop_config.options,
19
+ rubocop_config.config_store
20
+ )
21
+
22
+ time, run_succeeded = @timer.time {
23
+ runner.run(rubocop_config.paths)
24
+ }
25
+
26
+ if run_succeeded
27
+ puts "✨ Done in #{time.round(2)}s."
28
+ SUCCESS_STATUS_CODE
29
+ else
30
+ (runner.warnings + runner.errors).each do |message|
31
+ warn message
32
+ end
33
+ puts <<~CALL_TO_ACTION
34
+
35
+ Notice: Disagree with these rules? While StandardRB is pre-1.0.0, feel free to submit suggestions to:
36
+ https://github.com/testdouble/standard/issues/new
37
+ CALL_TO_ACTION
38
+ FAILURE_STATUS_CODE
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,100 @@
1
+ require "rubocop"
2
+ require "pathname"
3
+ require "yaml"
4
+ require_relative "file_finder"
5
+ require_relative "formatter"
6
+
7
+ module Standard
8
+ class Config
9
+ RuboCopConfig = Struct.new(:paths, :options, :config_store)
10
+
11
+ def initialize(argv)
12
+ filtered_argv, fix_flag = parse_argv(argv)
13
+ @rubocop_options, @paths = RuboCop::Options.new.parse(filtered_argv)
14
+ @standard_yml_path = FileFinder.new.call(".standard.yml", Dir.pwd)
15
+ @standard_config = init_standard_config(@standard_yml_path, fix_flag)
16
+ end
17
+
18
+ def to_rubocop
19
+ RuboCopConfig.new(
20
+ @paths,
21
+ wrap_rubocop_options(@rubocop_options),
22
+ RuboCop::ConfigStore.new.tap(&method(:mutate_config_store!))
23
+ )
24
+ end
25
+
26
+ private
27
+
28
+ # Filtered b/c RuboCop will switch to --only Layout when --fix is set (undocumented behavior)
29
+ def parse_argv(argv)
30
+ filtered_argv = argv.dup
31
+ fix_flag = !!filtered_argv.delete("--fix")
32
+ [filtered_argv, fix_flag]
33
+ end
34
+
35
+ def init_standard_config(yml_path, fix_flag)
36
+ user_config = if yml_path
37
+ YAML.load_file(Pathname.new(Dir.pwd).join(yml_path))
38
+ else
39
+ {}
40
+ end
41
+
42
+ {
43
+ :fix => fix_flag || !!user_config["fix"],
44
+ :format => user_config["format"],
45
+ :ignore => expand_ignore_config(user_config["ignore"]),
46
+ :parallel => !!user_config["parallel"],
47
+ :ruby_version => ruby_version(user_config["ruby_version"] || RUBY_VERSION)
48
+ }
49
+ end
50
+
51
+ def wrap_rubocop_options(rubocop_options)
52
+ {
53
+ :auto_correct => @standard_config[:fix],
54
+ :safe_auto_correct => @standard_config[:fix],
55
+ :formatters => [[@standard_config[:format] || "Standard::Formatter", nil]],
56
+ :parallel => @standard_config[:parallel]
57
+ }.merge(rubocop_options)
58
+ end
59
+
60
+ def mutate_config_store!(config_store)
61
+ config_store.options_config = Pathname.new(__dir__).join("../../config/base.yml")
62
+ options_config = config_store.instance_variable_get("@options_config")
63
+
64
+ options_config["AllCops"]["TargetRubyVersion"] = @standard_config[:ruby_version]
65
+
66
+ @standard_config[:ignore].each do |(path, cops)|
67
+ cops.each do |cop|
68
+ options_config[cop] ||= {}
69
+ options_config[cop]["Exclude"] ||= []
70
+ options_config[cop]["Exclude"] |= [Pathname.new(@standard_yml_path).dirname.join(path).to_s]
71
+ end
72
+ end
73
+ end
74
+
75
+ def expand_ignore_config(ignore_config)
76
+ arrayify(ignore_config).map { |rule|
77
+ if rule.is_a?(String)
78
+ [rule, ["AllCops"]]
79
+ elsif rule.is_a?(Hash)
80
+ rule.entries.first
81
+ end
82
+ }
83
+ end
84
+
85
+ def ruby_version(version)
86
+ major, minor = Gem::Version.new(version).segments
87
+ "#{major}.#{minor}".to_f # lol
88
+ end
89
+
90
+ def arrayify(object)
91
+ if object.nil?
92
+ []
93
+ elsif object.respond_to?(:to_ary)
94
+ object.to_ary || [object]
95
+ else
96
+ [object]
97
+ end
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,13 @@
1
+ require "pathname"
2
+
3
+ module Standard
4
+ class FileFinder
5
+ def call(name, search_path)
6
+ Pathname.new(search_path).expand_path.ascend do |path|
7
+ if (file = path + name).exist?
8
+ return file.to_s
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,25 @@
1
+ require "rubocop"
2
+
3
+ module Standard
4
+ class Formatter < RuboCop::Formatter::BaseFormatter
5
+ def file_finished(file, offenses)
6
+ uncorrected_offenses = offenses.reject(&:corrected?)
7
+ print_header_once unless uncorrected_offenses.empty?
8
+
9
+ uncorrected_offenses.each do |o|
10
+ output.printf(" %s:%d:%d: %s\n", file, o.line, o.real_column, o.message.tr("\n", " "))
11
+ end
12
+ end
13
+
14
+ private
15
+
16
+ def print_header_once
17
+ return if @header_printed_already
18
+ output.print <<~HEADER
19
+ standard: Use Ruby Standard Style (https://github.com/testdouble/standard)
20
+ standard: Run `standard --fix` to automatically fix some problems.
21
+ HEADER
22
+ @header_printed_already = true
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,13 @@
1
+ require "benchmark"
2
+
3
+ module Standard
4
+ class Timer
5
+ def time
6
+ result = false
7
+ time = Benchmark.realtime do
8
+ result = yield
9
+ end
10
+ [time, result]
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module Standard
2
+ VERSION = "0.0.4"
3
+ end
data/lib/standard.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "standard/version"
2
+ require "standard/cli"
3
+
4
+ module Standard
5
+ end
data/standard.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "standard/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "standard"
7
+ spec.version = Standard::VERSION
8
+ spec.authors = ["Justin Searls"]
9
+ spec.email = ["searls@gmail.com"]
10
+
11
+ spec.summary = "Ruby Style Guide, with linter & automatic code fixer"
12
+ spec.homepage = "https://github.com/testdouble/standard"
13
+
14
+ spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
15
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ end
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "rubocop", ">= 0.60"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.17"
24
+ spec.add_development_dependency "minitest", "~> 5.0"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: standard
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
+ platform: ruby
6
+ authors:
7
+ - Justin Searls
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-11-09 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.60'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0.60'
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.17'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.17'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ description:
70
+ email:
71
+ - searls@gmail.com
72
+ executables:
73
+ - standard
74
+ - standardrb
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - Gemfile
80
+ - Gemfile.lock
81
+ - README.md
82
+ - Rakefile
83
+ - bin/console
84
+ - bin/setup
85
+ - config/base.yml
86
+ - exe/standard
87
+ - exe/standardrb
88
+ - lib/standard.rb
89
+ - lib/standard/cli.rb
90
+ - lib/standard/config.rb
91
+ - lib/standard/file_finder.rb
92
+ - lib/standard/formatter.rb
93
+ - lib/standard/timer.rb
94
+ - lib/standard/version.rb
95
+ - standard.gemspec
96
+ homepage: https://github.com/testdouble/standard
97
+ licenses: []
98
+ metadata: {}
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 2.7.6
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: Ruby Style Guide, with linter & automatic code fixer
119
+ test_files: []