standard 0.3.0 → 0.4.4

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: 7368d84b38b7c89c397955507edcf80bec5faf78ec478c9f5b70969abd1f3cd8
4
- data.tar.gz: f74eb8f5da9fd6459c9aee08c16ab5a5de09392230e545e9812d29ac3d745720
3
+ metadata.gz: 52b7339d067d0811936bea5389c8b39efc85924dec8126a6f75ad1c673e5901e
4
+ data.tar.gz: 215b552f83cf2bb2a29e2771ccdc3eb64a8a9c939afcbb716bb185448e8f2fc0
5
5
  SHA512:
6
- metadata.gz: a357e1a42c1114344a68531cb65a22d2f82256dc98ce9b96ecea78959bae66a9beca785b266ec02d4f09ccbb2e3b2823ea30835682c917c2519b86c2e012b3f2
7
- data.tar.gz: 2acd01cc74605a7d97e367e24d439a22ee1aa8c3520d1da76f763a0491b2fff31bc3ab6d9884c14d7921f349d2d93039ea5346f3f64ad394574a177784a4ee42
6
+ metadata.gz: 7f91b781300a5bf99b633a56dc5408abf4af8089ed744b8b9b639f6869b36eb0f3ad666f98679f8f28733a354c97dd2834caa4921d184182979ec8314b9e48f6
7
+ data.tar.gz: 6cb189748d42164961d0e3af9340d74be4552db45ccbe1dad3ab125a27db36cc779025db04689eed1d2ba32361fb070222a9de48bbdc017bb3fcf4c54e26fa81
@@ -0,0 +1,34 @@
1
+ # Changelog
2
+
3
+ ## 0.4.4
4
+
5
+ * Disable `Naming/MethodName` cop. While `snake_case` is the conventional way to
6
+ name a Ruby method, the cop is too restrictive in that it also prevents
7
+ non-ASCII characters from being included in method names
8
+
9
+ ## 0.4.3
10
+
11
+ * Improve output of the todo feature
12
+
13
+ ## 0.4.2
14
+
15
+ * Track Rubocop
16
+ [0.83.0](https://github.com/rubocop-hq/rubocop/blob/master/CHANGELOG.md#0830-2020-05-11)
17
+ * Update our default to allow trailing whitespace in heredocs
18
+ * Disable auto-correct for a cop that changed `:true` to `true`, as that's not
19
+ safe
20
+ * Allow comments in empty `when` blocks
21
+
22
+
23
+ ## 0.4.1
24
+
25
+ * add given/given! as `{}` friendly blocks [#172](https://github.com/testdouble/standard/pull/172)
26
+
27
+ ## 0.4.0
28
+
29
+ * Add `--todo` mode for incremental adoption of Standard to a project ([PR](https://github.com/testdouble/standard/pull/155) by [@mrbiggred](https://github.com/mrbiggred))
30
+
31
+ ## 0.3.0
32
+
33
+ * Update Standard to track Rubocop 0.82.0 ([commit](https://github.com/testdouble/standard/commit/d663ea62d519c659087ad606bfed031c6303ff20))
34
+
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- standard (0.3.0)
5
- rubocop (~> 0.82.0)
4
+ standard (0.4.4)
5
+ rubocop (~> 0.83.0)
6
6
  rubocop-performance (~> 1.5.2)
7
7
 
8
8
  GEM
@@ -12,7 +12,6 @@ GEM
12
12
  coderay (1.1.2)
13
13
  docile (1.3.2)
14
14
  gimme (0.5.0)
15
- jaro_winkler (1.5.4)
16
15
  method_source (0.9.2)
17
16
  minitest (5.14.0)
18
17
  parallel (1.19.1)
@@ -24,8 +23,7 @@ GEM
24
23
  rainbow (3.0.0)
25
24
  rake (13.0.1)
26
25
  rexml (3.2.4)
27
- rubocop (0.82.0)
28
- jaro_winkler (~> 1.5.1)
26
+ rubocop (0.83.0)
29
27
  parallel (~> 1.10)
30
28
  parser (>= 2.7.0.1)
31
29
  rainbow (>= 2.2.2, < 4.0)
data/README.md CHANGED
@@ -47,7 +47,7 @@ flag.
47
47
  - **Leading dots on multi-line method chains** - chosen for
48
48
  [these](https://github.com/testdouble/standard/issues/75) reasons.
49
49
  - **Spaces inside blocks, but not hash literals** - In Ruby, the `{` and `}`
50
- characters do a lot of heavy lifting. To visually distinguish array literals
50
+ characters do a lot of heavy lifting. To visually distinguish hash literals
51
51
  from blocks, Standard enforces that (like arrays), no leading or trailing
52
52
  spaces be added to pad hashes
53
53
  - **And a good deal more**
@@ -88,6 +88,20 @@ $ bundle exec standardrb "lib/**/*.rb" test
88
88
  **Note:** by default, StandardRB will look for all `*.rb` files (and some other
89
89
  files typically associated with Ruby like `*.gemspec` and `Gemfile`)
90
90
 
91
+ If you have an existing project but aren't ready to fix all the files yet you can
92
+ generate a todo file:
93
+
94
+ ```bash
95
+ $ bundle exec standardrb --generate-todo
96
+ ```
97
+
98
+ This will create a `.standard_todo.yml` that lists all the files that contain errors.
99
+ When you run Standard in the future it will ignore these files as if they lived under the
100
+ `ignore` section in the `.standard.yml` file.
101
+
102
+ As you refactor your existing project you can remove files from the list. You can
103
+ also regenerate the todo file at anytime by re-running the above command.
104
+
91
105
  ### Using with Rake
92
106
 
93
107
  Standard also ships with Rake tasks. If you're using Rails, these should
@@ -120,7 +134,7 @@ $ rake standard STANDARDOPTS="lib \"app/**/*\""
120
134
  ## What you might do if you're clever
121
135
 
122
136
  If you want or need to configure Standard, there are a _handful_ of options
123
- are available creating a `.standard.yml` file in the root of your project.
137
+ available by creating a `.standard.yml` file in the root of your project.
124
138
 
125
139
  Here's an example yaml file with every option set:
126
140
 
@@ -143,11 +157,13 @@ cannot be found by ascending the current working directory (i.e., against a
143
157
  temporary file buffer in your editor), you can specify the config location with
144
158
  `--config path/to/.standard.yml`.
145
159
 
160
+ Similarly, for the `.standard_todo.yml` file, you can specify `--todo path/to/.standard_todo.yml`.
161
+
146
162
  ## What you might do if you're REALLY clever
147
163
 
148
164
  Because StandardRB is essentially a wrapper on top of
149
165
  [RuboCop](https://github.com/rubocop-hq/rubocop), it will actually forward the
150
- vast majority of CLI and ENV arguments forward to RuboCop.
166
+ vast majority of CLI and ENV arguments to RuboCop.
151
167
 
152
168
  You can see a list of
153
169
  [RuboCop](https://docs.rubocop.org/en/latest/basic_usage/#other-useful-command-line-flags)'s
@@ -241,7 +257,12 @@ problems are fixable, but some errors must be fixed manually.
241
257
 
242
258
  ## Can I override the `fix: true` config setting?
243
259
 
244
- Also yes! You can use `standardrb --no-fix`. Not `fix`ing is the default behavior, but this flag will override the `fix: true` setting in your [`.standard.yml` config](#what-you-might-do-if-youre-clever). This is especially useful for checking your projects compliance with `standardrb` in CI environments while keeping the `fix: true` option enabled locally.
260
+ Also yes! You can use `standardrb --no-fix`. Not `fix`ing is the default
261
+ behavior, but this flag will override the `fix: true` setting in your
262
+ [`.standard.yml` config](#what-you-might-do-if-youre-clever).
263
+ This is especially useful for checking your project's compliance with
264
+ `standardrb` in CI environments while keeping the `fix: true` option enabled
265
+ locally.
245
266
 
246
267
  ## How do I ignore files?
247
268
 
@@ -361,6 +382,7 @@ from editor plugins:
361
382
 
362
383
  * [Pronto](https://github.com/julianrubisch/pronto-standardrb)
363
384
  * [Spring](https://github.com/lakim/spring-commands-standard)
385
+ * [Guard](https://github.com/JodyVanden/guard-standardrb)
364
386
 
365
387
  ## Contributing
366
388
 
@@ -312,7 +312,7 @@ Layout/TrailingEmptyLines:
312
312
 
313
313
  Layout/TrailingWhitespace:
314
314
  Enabled: true
315
- AllowInHeredoc: false
315
+ AllowInHeredoc: true
316
316
 
317
317
  Lint/AmbiguousOperator:
318
318
  Enabled: true
@@ -329,7 +329,6 @@ Lint/BigDecimalNew:
329
329
 
330
330
  Lint/BooleanSymbol:
331
331
  Enabled: true
332
- AutoCorrect: true
333
332
 
334
333
  Lint/CircularArgumentReference:
335
334
  Enabled: true
@@ -367,6 +366,7 @@ Lint/EmptyInterpolation:
367
366
 
368
367
  Lint/EmptyWhen:
369
368
  Enabled: true
369
+ AllowComments: true
370
370
 
371
371
  Lint/EnsureReturn:
372
372
  Enabled: true
@@ -553,10 +553,6 @@ Naming/HeredocDelimiterCase:
553
553
  Enabled: true
554
554
  EnforcedStyle: uppercase
555
555
 
556
- Naming/MethodName:
557
- Enabled: true
558
- EnforcedStyle: snake_case
559
-
560
556
  Naming/BlockParameterName:
561
557
  Enabled: true
562
558
  MinNameLength: 1
@@ -667,6 +663,8 @@ Standard/SemanticBlocks:
667
663
  # Rails
668
664
  - transaction
669
665
  FunctionalMethods:
666
+ - given
667
+ - given!
670
668
  - let
671
669
  - let!
672
670
  - subject
@@ -7,13 +7,17 @@ module Standard
7
7
 
8
8
  class BuildsConfig
9
9
  def initialize
10
+ @parses_cli_option = ParsesCliOption.new
10
11
  @loads_yaml_config = LoadsYamlConfig.new
11
12
  @merges_settings = MergesSettings.new
12
13
  @creates_config_store = CreatesConfigStore.new
13
14
  end
14
15
 
15
16
  def call(argv, search_path = Dir.pwd)
16
- standard_config = @loads_yaml_config.call(argv, search_path)
17
+ standard_yaml_path = determine_yaml_file(argv, search_path, "--config", ".standard.yml")
18
+ todo_yaml_path = determine_yaml_file(argv, search_path, "--todo", ".standard_todo.yml")
19
+ standard_config = @loads_yaml_config.call(standard_yaml_path, todo_yaml_path)
20
+
17
21
  settings = @merges_settings.call(argv, standard_config)
18
22
  Config.new(
19
23
  settings.runner,
@@ -22,5 +26,11 @@ module Standard
22
26
  @creates_config_store.call(standard_config)
23
27
  )
24
28
  end
29
+
30
+ private
31
+
32
+ def determine_yaml_file(argv, search_path, option_name, default_file)
33
+ @parses_cli_option.call(argv, option_name) || FileFinder.new.call(default_file, search_path)
34
+ end
25
35
  end
26
36
  end
@@ -1,3 +1,4 @@
1
+ require "yaml"
1
2
  require "rubocop"
2
3
  require_relative "detects_fixability"
3
4
 
@@ -16,6 +17,10 @@ module Standard
16
17
  @any_uncorrected_offenses = false
17
18
  end
18
19
 
20
+ def started(_target_files)
21
+ print_todo_warning
22
+ end
23
+
19
24
  def file_finished(file, offenses)
20
25
  return unless (uncorrected_offenses = offenses.reject(&:corrected?)).any?
21
26
  @any_uncorrected_offenses = true
@@ -59,6 +64,22 @@ module Standard
59
64
  end
60
65
  end
61
66
 
67
+ def print_todo_warning
68
+ todo_file = options[:todo_file]
69
+ return unless todo_file
70
+
71
+ todo_ignore_files = options[:todo_ignore_files]
72
+ return unless todo_ignore_files
73
+
74
+ output.print <<-HEADER.gsub(/^ {8}/, "")
75
+ WARNING: this project is being migrated to standard gradually via `#{todo_file}` and is ignoring these files:
76
+ HEADER
77
+
78
+ todo_ignore_files.each do |f|
79
+ output.printf(" %s\n", f)
80
+ end
81
+ end
82
+
62
83
  def path_to(file)
63
84
  Pathname.new(file).relative_path_from(Pathname.new(Dir.pwd))
64
85
  end
@@ -5,14 +5,11 @@ require_relative "parses_cli_option"
5
5
 
6
6
  module Standard
7
7
  class LoadsYamlConfig
8
- def initialize
9
- @parses_cli_option = ParsesCliOption.new
10
- end
8
+ def call(standard_yaml_path, todo_yaml_path)
9
+ standard_yaml = load_standard_yaml(standard_yaml_path)
10
+ todo_yaml = load_standard_yaml(todo_yaml_path)
11
11
 
12
- def call(argv, search_path)
13
- yaml_path = @parses_cli_option.call(argv, "--config") ||
14
- FileFinder.new.call(".standard.yml", search_path)
15
- construct_config(yaml_path, load_standard_yaml(yaml_path))
12
+ construct_config(standard_yaml_path, standard_yaml, todo_yaml_path, todo_yaml)
16
13
  end
17
14
 
18
15
  private
@@ -25,15 +22,17 @@ module Standard
25
22
  end
26
23
  end
27
24
 
28
- def construct_config(yaml_path, standard_yaml)
25
+ def construct_config(yaml_path, standard_yaml, todo_path, todo_yaml)
29
26
  {
30
27
  ruby_version: Gem::Version.new((standard_yaml["ruby_version"] || RUBY_VERSION)),
31
28
  fix: !!standard_yaml["fix"],
32
29
  format: standard_yaml["format"],
33
30
  parallel: !!standard_yaml["parallel"],
34
- ignore: expand_ignore_config(standard_yaml["ignore"]),
31
+ ignore: expand_ignore_config(standard_yaml["ignore"]) + expand_ignore_config(todo_yaml["ignore"]),
35
32
  default_ignores: standard_yaml.key?("default_ignores") ? !!standard_yaml["default_ignores"] : true,
36
- config_root: yaml_path ? Pathname.new(yaml_path).dirname.to_s : nil
33
+ config_root: yaml_path ? Pathname.new(yaml_path).dirname.to_s : nil,
34
+ todo_file: todo_path,
35
+ todo_ignore_files: todo_yaml["ignore"] || []
37
36
  }
38
37
  end
39
38
 
@@ -20,7 +20,7 @@ module Standard
20
20
 
21
21
  def separate_argv(argv)
22
22
  argv.partition { |flag|
23
- ["--fix", "--no-fix", "--version", "-v", "--help", "-h"].include?(flag)
23
+ ["--generate-todo", "--fix", "--no-fix", "--version", "-v", "--help", "-h"].include?(flag)
24
24
  }
25
25
  end
26
26
 
@@ -41,6 +41,8 @@ module Standard
41
41
  :help
42
42
  elsif (argv & ["--version", "-v"]).any?
43
43
  :version
44
+ elsif (argv & ["--generate-todo"]).any?
45
+ :genignore
44
46
  else
45
47
  :rubocop
46
48
  end
@@ -51,7 +53,9 @@ module Standard
51
53
  auto_correct: standard_yaml[:fix],
52
54
  safe_auto_correct: standard_yaml[:fix],
53
55
  formatters: [[standard_yaml[:format] || "Standard::Formatter", nil]],
54
- parallel: standard_yaml[:parallel]
56
+ parallel: standard_yaml[:parallel],
57
+ todo_file: standard_yaml[:todo_file],
58
+ todo_ignore_files: standard_yaml[:todo_ignore_files]
55
59
  }.merge(standard_cli_flags).merge(rubocop_cli_flags)
56
60
  end
57
61
 
@@ -0,0 +1,48 @@
1
+ require "tempfile"
2
+ require "yaml"
3
+ require_relative "rubocop"
4
+
5
+ module Standard
6
+ module Runners
7
+ class Genignore
8
+ def call(config)
9
+ # Place to temporally store the ignored files.
10
+ temp_file = Tempfile.new("excluded.txt")
11
+ begin
12
+ # Run Rubocop to generate the files with errors into the temp file.
13
+ config.rubocop_options[:formatters] = [["files", temp_file.path]]
14
+ config.rubocop_options[:format] = "files"
15
+ config.rubocop_options[:out] = temp_file.path
16
+ Runners::Rubocop.new.call(config)
17
+
18
+ # Read in the files with errors. It will have the absolute paths
19
+ # of the files but we only want the relative path.
20
+ files_with_errors = temp_file.readlines.map(&:chomp)
21
+ files_with_errors.map! do |file|
22
+ # Get the relative file path. Don't use the
23
+ # relative_path_from method as it will raise an
24
+ # error in Ruby 2.4.1 and possibly other versions.
25
+ #
26
+ # https://bugs.ruby-lang.org/issues/10011
27
+ #
28
+ file.sub(Dir.pwd + File::SEPARATOR, "")
29
+ end
30
+
31
+ # Read the files with errors from the temp file.
32
+ yaml_format_errors = {"ignore" => files_with_errors}
33
+
34
+ # Regenerate the todo file.
35
+ File.open(".standard_todo.yml", "w") do |file|
36
+ file.puts "# Auto generated files with errors to ignore."
37
+ file.puts "# Remove from this list as you refactor files."
38
+ file.write(yaml_format_errors.to_yaml)
39
+ end
40
+ ensure
41
+ # Clean up temp file.
42
+ temp_file.close
43
+ temp_file.unlink
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -1,3 +1,3 @@
1
1
  module Standard
2
- VERSION = Gem::Version.new("0.3.0")
2
+ VERSION = Gem::Version.new("0.4.4")
3
3
  end
@@ -7,6 +7,7 @@ Gem::Specification.new do |spec|
7
7
  spec.version = Standard::VERSION
8
8
  spec.authors = ["Justin Searls"]
9
9
  spec.email = ["searls@gmail.com"]
10
+ spec.required_ruby_version = ">= 2.4.0"
10
11
 
11
12
  spec.summary = "Ruby Style Guide, with linter & automatic code fixer"
12
13
  spec.homepage = "https://github.com/testdouble/standard"
@@ -18,7 +19,7 @@ Gem::Specification.new do |spec|
18
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
20
  spec.require_paths = ["lib"]
20
21
 
21
- spec.add_dependency "rubocop", "~> 0.82.0"
22
+ spec.add_dependency "rubocop", "~> 0.83.0"
22
23
  spec.add_dependency "rubocop-performance", "~> 1.5.2"
23
24
 
24
25
  spec.add_development_dependency "bundler"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: standard
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Searls
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-04 00:00:00.000000000 Z
11
+ date: 2020-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.82.0
19
+ version: 0.83.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.82.0
26
+ version: 0.83.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rubocop-performance
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -133,6 +133,7 @@ files:
133
133
  - ".circleci/config.yml"
134
134
  - ".gitignore"
135
135
  - ".standard.yml"
136
+ - CHANGELOG.md
136
137
  - Gemfile
137
138
  - Gemfile.lock
138
139
  - LICENSE.txt
@@ -163,6 +164,7 @@ files:
163
164
  - lib/standard/railtie.rb
164
165
  - lib/standard/rake.rb
165
166
  - lib/standard/rubocop/ext.rb
167
+ - lib/standard/runners/genignore.rb
166
168
  - lib/standard/runners/help.rb
167
169
  - lib/standard/runners/rubocop.rb
168
170
  - lib/standard/runners/version.rb
@@ -179,7 +181,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
179
181
  requirements:
180
182
  - - ">="
181
183
  - !ruby/object:Gem::Version
182
- version: '0'
184
+ version: 2.4.0
183
185
  required_rubygems_version: !ruby/object:Gem::Requirement
184
186
  requirements:
185
187
  - - ">="