standard 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/Gemfile.lock +1 -1
- data/README.md +16 -0
- data/lib/standard/builds_config.rb +11 -1
- data/lib/standard/formatter.rb +18 -0
- data/lib/standard/loads_yaml_config.rb +9 -10
- data/lib/standard/merges_settings.rb +6 -2
- data/lib/standard/runners/genignore.rb +48 -0
- data/lib/standard/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e4c53488a0de2cfd83d5a709a948b34f8cc824e4c6e12112f9a54b639b0f8b52
|
4
|
+
data.tar.gz: 2ee6d881d29a8f0c1e97f8463973cf98673b709f5771f445313395f07e382958
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 125bfbc5932e5dc79d05716189735a492b7ec334912397dcd002b322ae88eec59513fc6969b512b423aa9a9d87c4ce333ab03d75970d9d0edabe2b93ca4ed417
|
7
|
+
data.tar.gz: 72e9e47eb341377a3de943609d6e368d00e3e60940b5b45eec3654d9f3b12cd135cb1d1c4265d21b819b9a41ec8fc12b5e22bfe9e2860705025fc068ade64519
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## 0.4.0
|
4
|
+
|
5
|
+
* 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))
|
6
|
+
|
7
|
+
## 0.3.0
|
8
|
+
|
9
|
+
* Update Standard to track Rubocop 0.82.0 ([commit](https://github.com/testdouble/standard/commit/d663ea62d519c659087ad606bfed031c6303ff20))
|
10
|
+
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -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
|
@@ -143,6 +157,8 @@ 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
|
@@ -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
|
-
|
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
|
data/lib/standard/formatter.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require "yaml"
|
1
2
|
require "rubocop"
|
2
3
|
require_relative "detects_fixability"
|
3
4
|
|
@@ -29,6 +30,7 @@ module Standard
|
|
29
30
|
end
|
30
31
|
|
31
32
|
def finished(_)
|
33
|
+
print_todo_warning
|
32
34
|
print_call_for_feedback if @any_uncorrected_offenses
|
33
35
|
end
|
34
36
|
|
@@ -59,6 +61,22 @@ module Standard
|
|
59
61
|
end
|
60
62
|
end
|
61
63
|
|
64
|
+
def print_todo_warning
|
65
|
+
todo_file = options[:todo_file]
|
66
|
+
return unless todo_file
|
67
|
+
|
68
|
+
todo_ignore_files = options[:todo_ignore_files]
|
69
|
+
return unless todo_ignore_files
|
70
|
+
|
71
|
+
output.print <<-HEADER.gsub(/^ {8}/, "")
|
72
|
+
WARNING: this project is being migrated to standard gradually via `#{todo_file}` and is ignoring these files:
|
73
|
+
HEADER
|
74
|
+
|
75
|
+
todo_ignore_files.each do |f|
|
76
|
+
output.printf(" %s\n", f)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
62
80
|
def path_to(file)
|
63
81
|
Pathname.new(file).relative_path_from(Pathname.new(Dir.pwd))
|
64
82
|
end
|
@@ -5,14 +5,11 @@ require_relative "parses_cli_option"
|
|
5
5
|
|
6
6
|
module Standard
|
7
7
|
class LoadsYamlConfig
|
8
|
-
def
|
9
|
-
|
10
|
-
|
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
|
-
|
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
|
data/lib/standard/version.rb
CHANGED
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.
|
4
|
+
version: 0.4.0
|
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-
|
11
|
+
date: 2020-05-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|
@@ -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
|