standard 0.1.0 → 1.51.1

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.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +11 -0
  3. data/.github/workflows/test.yml +24 -0
  4. data/.github/workflows/update.yml +54 -0
  5. data/.gitignore +3 -0
  6. data/.standard.yml +1 -1
  7. data/CHANGELOG.md +703 -0
  8. data/Gemfile +13 -0
  9. data/Gemfile.lock +71 -37
  10. data/LICENSE.txt +3 -4
  11. data/README.md +459 -264
  12. data/Rakefile +5 -4
  13. data/bin/console +0 -4
  14. data/bin/rake +27 -0
  15. data/bin/run +9 -0
  16. data/config/base.yml +1065 -193
  17. data/config/default.yml +8 -0
  18. data/config/ruby-1.8.yml +10 -2
  19. data/config/ruby-1.9.yml +11 -1
  20. data/config/ruby-2.0.yml +4 -0
  21. data/config/ruby-2.1.yml +4 -0
  22. data/config/ruby-2.2.yml +13 -5
  23. data/config/ruby-2.3.yml +10 -0
  24. data/config/ruby-2.4.yml +10 -0
  25. data/config/ruby-2.5.yml +10 -0
  26. data/config/ruby-2.6.yml +13 -0
  27. data/config/ruby-2.7.yml +10 -0
  28. data/config/ruby-3.0.yml +13 -0
  29. data/config/ruby-3.1.yml +11 -0
  30. data/config/ruby-3.2.yml +4 -0
  31. data/config/ruby-3.3.yml +7 -0
  32. data/docs/ARCHITECTURE.md +33 -0
  33. data/docs/RELEASE.md +41 -0
  34. data/docs/RUBY_VERSIONS.md +51 -0
  35. data/docs/UPGRADING.md +31 -0
  36. data/lib/ruby_lsp/standard/addon.rb +58 -0
  37. data/lib/ruby_lsp/standard/wraps_built_in_lsp_standardizer.rb +44 -0
  38. data/lib/standard/base/plugin.rb +69 -0
  39. data/lib/standard/base.rb +8 -0
  40. data/lib/standard/builds_config.rb +11 -1
  41. data/lib/standard/cli.rb +1 -7
  42. data/lib/standard/creates_config_store/assigns_rubocop_yaml.rb +2 -18
  43. data/lib/standard/creates_config_store/configures_ignored_paths.rb +2 -2
  44. data/lib/standard/creates_config_store/merges_user_config_extensions.rb +37 -0
  45. data/lib/standard/creates_config_store/sets_target_ruby_version.rb +21 -8
  46. data/lib/standard/creates_config_store.rb +5 -0
  47. data/lib/standard/formatter.rb +92 -37
  48. data/lib/standard/loads_runner.rb +17 -3
  49. data/lib/standard/loads_yaml_config.rb +18 -11
  50. data/lib/standard/lsp/diagnostic.rb +174 -0
  51. data/lib/standard/lsp/kills_server.rb +10 -0
  52. data/lib/standard/lsp/logger.rb +21 -0
  53. data/lib/standard/lsp/routes.rb +175 -0
  54. data/lib/standard/lsp/server.rb +37 -0
  55. data/lib/standard/lsp/standardizer.rb +34 -0
  56. data/lib/standard/lsp/stdin_rubocop_runner.rb +71 -0
  57. data/lib/standard/merges_settings.rb +22 -11
  58. data/lib/standard/plugin/combines_plugin_configs.rb +15 -0
  59. data/lib/standard/plugin/creates_runner_context.rb +15 -0
  60. data/lib/standard/plugin/determines_class_constant.rb +56 -0
  61. data/lib/standard/plugin/initializes_plugins.rb +23 -0
  62. data/lib/standard/plugin/merges_plugins_into_rubocop_config.rb +177 -0
  63. data/lib/standard/plugin/standardizes_configured_plugins.rb +37 -0
  64. data/lib/standard/plugin.rb +11 -0
  65. data/lib/standard/railtie.rb +1 -1
  66. data/lib/standard/rake.rb +8 -1
  67. data/lib/standard/{parses_cli_option.rb → resolves_yaml_option.rb} +9 -2
  68. data/lib/standard/rubocop/ext.rb +17 -0
  69. data/lib/standard/runners/genignore.rb +44 -0
  70. data/lib/standard/runners/help.rb +9 -5
  71. data/lib/standard/runners/lsp.rb +11 -0
  72. data/lib/standard/runners/rubocop.rb +14 -18
  73. data/lib/standard/runners/verbose_version.rb +14 -0
  74. data/lib/standard/version.rb +1 -1
  75. data/lib/standard.rb +6 -4
  76. data/standard.gemspec +22 -20
  77. metadata +72 -73
  78. data/.circleci/config.yml +0 -35
  79. data/lib/standard/cop/semantic_blocks.rb +0 -162
  80. data/lib/standard/detects_fixability.rb +0 -20
@@ -1,162 +0,0 @@
1
- module RuboCop::Cop
2
- module Standard
3
- class SemanticBlocks < RuboCop::Cop::Cop
4
- include RuboCop::Cop::IgnoredMethods
5
-
6
- def on_send(node)
7
- return unless node.arguments?
8
- return if node.parenthesized? || node.operator_method?
9
-
10
- node.arguments.each do |arg|
11
- get_blocks(arg) do |block|
12
- # If there are no parentheses around the arguments, then braces
13
- # and do-end have different meaning due to how they bind, so we
14
- # allow either.
15
- ignore_node(block)
16
- end
17
- end
18
- end
19
-
20
- def on_block(node)
21
- return if ignored_node?(node) || proper_block_style?(node)
22
-
23
- add_offense(node, location: :begin)
24
- end
25
-
26
- def autocorrect(node)
27
- return if correction_would_break_code?(node)
28
-
29
- if node.single_line?
30
- replace_do_end_with_braces(node.loc)
31
- elsif node.braces?
32
- replace_braces_with_do_end(node.loc)
33
- else
34
- replace_do_end_with_braces(node.loc)
35
- end
36
- end
37
-
38
- private
39
-
40
- def message(node)
41
- if node.single_line?
42
- "Prefer `{...}` over `do...end` for single-line blocks."
43
- elsif node.loc.begin.source == "{"
44
- "Prefer `do...end` over `{...}` for procedural blocks."
45
- else
46
- "Prefer `{...}` over `do...end` for functional blocks."
47
- end
48
- end
49
-
50
- def replace_braces_with_do_end(loc)
51
- b = loc.begin
52
- e = loc.end
53
-
54
- lambda do |corrector|
55
- corrector.insert_before(b, " ") unless whitespace_before?(b)
56
- corrector.insert_before(e, " ") unless whitespace_before?(e)
57
- corrector.insert_after(b, " ") unless whitespace_after?(b)
58
- corrector.replace(b, "do")
59
- corrector.replace(e, "end")
60
- end
61
- end
62
-
63
- def replace_do_end_with_braces(loc)
64
- b = loc.begin
65
- e = loc.end
66
-
67
- lambda do |corrector|
68
- corrector.insert_after(b, " ") unless whitespace_after?(b, 2)
69
-
70
- corrector.replace(b, "{")
71
- corrector.replace(e, "}")
72
- end
73
- end
74
-
75
- def whitespace_before?(range)
76
- range.source_buffer.source[range.begin_pos - 1, 1] =~ /\s/
77
- end
78
-
79
- def whitespace_after?(range, length = 1)
80
- range.source_buffer.source[range.begin_pos + length, 1] =~ /\s/
81
- end
82
-
83
- def get_blocks(node, &block)
84
- case node.type
85
- when :block
86
- yield node
87
- when :send
88
- get_blocks(node.receiver, &block) if node.receiver
89
- when :hash
90
- # A hash which is passed as method argument may have no braces
91
- # In that case, one of the K/V pairs could contain a block node
92
- # which could change in meaning if do...end replaced {...}
93
- return if node.braces?
94
-
95
- node.each_child_node { |child| get_blocks(child, &block) }
96
- when :pair
97
- node.each_child_node { |child| get_blocks(child, &block) }
98
- end
99
- end
100
-
101
- def proper_block_style?(node)
102
- method_name = node.method_name
103
-
104
- if ignored_method?(method_name)
105
- true
106
- elsif node.single_line?
107
- node.braces?
108
- elsif node.braces?
109
- !procedural_method?(method_name) &&
110
- (functional_method?(method_name) || functional_block?(node))
111
- else
112
- procedural_method?(method_name) || !return_value_used?(node)
113
- end
114
- end
115
-
116
- def correction_would_break_code?(node)
117
- return unless node.keywords?
118
-
119
- node.send_node.arguments? && !node.send_node.parenthesized?
120
- end
121
-
122
- def functional_method?(method_name)
123
- cop_config["FunctionalMethods"].map(&:to_sym).include?(method_name)
124
- end
125
-
126
- def functional_block?(node)
127
- return_value_used?(node) || return_value_of_scope?(node)
128
- end
129
-
130
- def procedural_method?(method_name)
131
- cop_config["ProceduralMethods"].map(&:to_sym).include?(method_name)
132
- end
133
-
134
- def return_value_used?(node)
135
- return unless node.parent
136
-
137
- # If there are parentheses around the block, check if that
138
- # is being used.
139
- if node.parent.begin_type?
140
- return_value_used?(node.parent)
141
- else
142
- node.parent.assignment? || node.parent.send_type?
143
- end
144
- end
145
-
146
- def return_value_of_scope?(node)
147
- return unless node.parent
148
-
149
- conditional?(node.parent) || array_or_range?(node.parent) ||
150
- node.parent.children.last == node
151
- end
152
-
153
- def conditional?(node)
154
- node.if_type? || node.or_type? || node.and_type?
155
- end
156
-
157
- def array_or_range?(node)
158
- node.array_type? || node.irange_type? || node.erange_type?
159
- end
160
- end
161
- end
162
- end
@@ -1,20 +0,0 @@
1
- module Standard
2
- class DetectsFixability
3
- def call(offenses)
4
- offenses.any? { |offense|
5
- cop = cop_instance(offense.cop_name)
6
- cop.support_autocorrect? && safe?(cop)
7
- }
8
- end
9
-
10
- private
11
-
12
- def cop_instance(cop_name)
13
- RuboCop::Cop.const_get(cop_name.gsub("/", "::")).new
14
- end
15
-
16
- def safe?(cop)
17
- cop.cop_config.fetch("SafeAutoCorrect", true)
18
- end
19
- end
20
- end