rubocop 1.30.1 → 1.31.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/config/default.yml +41 -8
- data/config/obsoletion.yml +2 -0
- data/exe/rubocop +15 -7
- data/lib/rubocop/cli/command/auto_genenerate_config.rb +1 -1
- data/lib/rubocop/cli/command/suggest_extensions.rb +3 -3
- data/lib/rubocop/config.rb +4 -0
- data/lib/rubocop/config_loader.rb +1 -0
- data/lib/rubocop/config_loader_resolver.rb +1 -1
- data/lib/rubocop/config_validator.rb +3 -3
- data/lib/rubocop/cop/base.rb +5 -1
- data/lib/rubocop/cop/bundler/duplicated_gem.rb +1 -1
- data/lib/rubocop/cop/bundler/gem_filename.rb +4 -4
- data/lib/rubocop/cop/bundler/ordered_gems.rb +2 -2
- data/lib/rubocop/cop/corrector.rb +2 -2
- data/lib/rubocop/cop/correctors/multiline_literal_brace_corrector.rb +3 -3
- data/lib/rubocop/cop/correctors/unused_arg_corrector.rb +1 -1
- data/lib/rubocop/cop/gemspec/deprecated_attribute_assignment.rb +31 -16
- data/lib/rubocop/cop/gemspec/duplicated_assignment.rb +1 -1
- data/lib/rubocop/cop/gemspec/ordered_dependencies.rb +1 -1
- data/lib/rubocop/cop/gemspec/require_mfa.rb +20 -20
- data/lib/rubocop/cop/generator.rb +5 -1
- data/lib/rubocop/cop/internal_affairs/node_matcher_directive.rb +1 -5
- data/lib/rubocop/cop/internal_affairs/redundant_location_argument.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/redundant_message_argument.rb +1 -1
- data/lib/rubocop/cop/internal_affairs/useless_restrict_on_send.rb +54 -0
- data/lib/rubocop/cop/internal_affairs.rb +1 -0
- data/lib/rubocop/cop/layout/empty_comment.rb +1 -1
- data/lib/rubocop/cop/layout/empty_lines_around_attribute_accessor.rb +25 -4
- data/lib/rubocop/cop/layout/first_array_element_indentation.rb +20 -13
- data/lib/rubocop/cop/layout/first_hash_element_indentation.rb +51 -12
- data/lib/rubocop/cop/layout/initial_indentation.rb +1 -1
- data/lib/rubocop/cop/layout/line_continuation_leading_space.rb +68 -0
- data/lib/rubocop/cop/layout/line_continuation_spacing.rb +130 -0
- data/lib/rubocop/cop/layout/multiline_block_layout.rb +1 -1
- data/lib/rubocop/cop/layout/multiline_method_call_indentation.rb +2 -2
- data/lib/rubocop/cop/layout/multiline_operation_indentation.rb +2 -2
- data/lib/rubocop/cop/layout/space_around_block_parameters.rb +1 -1
- data/lib/rubocop/cop/layout/space_around_operators.rb +1 -1
- data/lib/rubocop/cop/layout/space_before_block_braces.rb +1 -1
- data/lib/rubocop/cop/layout/space_before_first_arg.rb +1 -1
- data/lib/rubocop/cop/layout/space_inside_block_braces.rb +5 -3
- data/lib/rubocop/cop/layout/trailing_whitespace.rb +1 -1
- data/lib/rubocop/cop/lint/constant_overwritten_in_rescue.rb +51 -0
- data/lib/rubocop/cop/lint/interpolation_check.rb +1 -1
- data/lib/rubocop/cop/lint/literal_as_condition.rb +5 -0
- data/lib/rubocop/cop/lint/non_atomic_file_operation.rb +126 -0
- data/lib/rubocop/cop/lint/number_conversion.rb +3 -3
- data/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +1 -1
- data/lib/rubocop/cop/lint/redundant_cop_disable_directive.rb +5 -5
- data/lib/rubocop/cop/lint/redundant_cop_enable_directive.rb +1 -1
- data/lib/rubocop/cop/lint/redundant_require_statement.rb +1 -1
- data/lib/rubocop/cop/lint/regexp_as_condition.rb +2 -2
- data/lib/rubocop/cop/lint/struct_new_override.rb +2 -2
- data/lib/rubocop/cop/lint/trailing_comma_in_attribute_declaration.rb +1 -1
- data/lib/rubocop/cop/lint/useless_else_without_rescue.rb +44 -0
- data/lib/rubocop/cop/metrics/utils/code_length_calculator.rb +1 -1
- data/lib/rubocop/cop/mixin/def_node.rb +2 -7
- data/lib/rubocop/cop/mixin/multiline_element_indentation.rb +34 -12
- data/lib/rubocop/cop/mixin/range_help.rb +7 -3
- data/lib/rubocop/cop/style/accessor_grouping.rb +1 -1
- data/lib/rubocop/cop/style/arguments_forwarding.rb +1 -1
- data/lib/rubocop/cop/style/block_delimiters.rb +4 -2
- data/lib/rubocop/cop/style/commented_keyword.rb +1 -1
- data/lib/rubocop/cop/style/conditional_assignment.rb +1 -0
- data/lib/rubocop/cop/style/empty_method.rb +16 -1
- data/lib/rubocop/cop/style/encoding.rb +1 -1
- data/lib/rubocop/cop/style/explicit_block_argument.rb +1 -1
- data/lib/rubocop/cop/style/format_string_token.rb +48 -17
- data/lib/rubocop/cop/style/frozen_string_literal_comment.rb +1 -1
- data/lib/rubocop/cop/style/guard_clause.rb +8 -6
- data/lib/rubocop/cop/style/hash_as_last_array_item.rb +1 -1
- data/lib/rubocop/cop/style/hash_except.rb +88 -8
- data/lib/rubocop/cop/style/hash_syntax.rb +2 -2
- data/lib/rubocop/cop/style/implicit_runtime_error.rb +2 -2
- data/lib/rubocop/cop/style/keyword_parameters_order.rb +1 -1
- data/lib/rubocop/cop/style/line_end_concatenation.rb +1 -1
- data/lib/rubocop/cop/style/map_to_hash.rb +1 -1
- data/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +2 -2
- data/lib/rubocop/cop/style/module_function.rb +2 -2
- data/lib/rubocop/cop/style/multiline_if_modifier.rb +2 -2
- data/lib/rubocop/cop/style/multiline_if_then.rb +1 -1
- data/lib/rubocop/cop/style/multiline_in_pattern_then.rb +1 -3
- data/lib/rubocop/cop/style/multiline_method_signature.rb +1 -1
- data/lib/rubocop/cop/style/multiline_ternary_operator.rb +1 -1
- data/lib/rubocop/cop/style/multiline_when_then.rb +1 -3
- data/lib/rubocop/cop/style/nested_parenthesized_calls.rb +1 -1
- data/lib/rubocop/cop/style/nested_ternary_operator.rb +19 -7
- data/lib/rubocop/cop/style/nil_lambda.rb +1 -1
- data/lib/rubocop/cop/style/not.rb +1 -1
- data/lib/rubocop/cop/style/redundant_argument.rb +1 -1
- data/lib/rubocop/cop/style/redundant_parentheses.rb +2 -1
- data/lib/rubocop/cop/style/redundant_return.rb +1 -1
- data/lib/rubocop/cop/style/redundant_self_assignment.rb +1 -1
- data/lib/rubocop/cop/style/sole_nested_conditional.rb +2 -2
- data/lib/rubocop/cop/style/struct_inheritance.rb +2 -2
- data/lib/rubocop/cop/style/swap_values.rb +1 -1
- data/lib/rubocop/cop/style/symbol_proc.rb +1 -1
- data/lib/rubocop/cop/style/top_level_method_definition.rb +0 -2
- data/lib/rubocop/cop/style/unpack_first.rb +1 -1
- data/lib/rubocop/cop/util.rb +1 -1
- data/lib/rubocop/formatter/formatter_set.rb +20 -19
- data/lib/rubocop/formatter/git_hub_actions_formatter.rb +15 -2
- data/lib/rubocop/formatter/html_formatter.rb +0 -1
- data/lib/rubocop/formatter/offense_count_formatter.rb +2 -0
- data/lib/rubocop/formatter/simple_text_formatter.rb +6 -7
- data/lib/rubocop/formatter.rb +31 -0
- data/lib/rubocop/options.rb +24 -1
- data/lib/rubocop/rake_task.rb +34 -9
- data/lib/rubocop/server/cache.rb +109 -0
- data/lib/rubocop/server/cli.rb +104 -0
- data/lib/rubocop/server/client_command/base.rb +44 -0
- data/lib/rubocop/server/client_command/exec.rb +59 -0
- data/lib/rubocop/server/client_command/restart.rb +25 -0
- data/lib/rubocop/server/client_command/start.rb +43 -0
- data/lib/rubocop/server/client_command/status.rb +28 -0
- data/lib/rubocop/server/client_command/stop.rb +31 -0
- data/lib/rubocop/server/client_command.rb +26 -0
- data/lib/rubocop/server/core.rb +79 -0
- data/lib/rubocop/server/errors.rb +23 -0
- data/lib/rubocop/server/helper.rb +34 -0
- data/lib/rubocop/server/server_command/base.rb +50 -0
- data/lib/rubocop/server/server_command/exec.rb +34 -0
- data/lib/rubocop/server/server_command/stop.rb +24 -0
- data/lib/rubocop/server/server_command.rb +21 -0
- data/lib/rubocop/server/socket_reader.rb +65 -0
- data/lib/rubocop/server.rb +53 -0
- data/lib/rubocop/version.rb +15 -8
- data/lib/rubocop.rb +8 -27
- metadata +42 -4
- data/lib/rubocop/cop/gemspec/date_assignment.rb +0 -49
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# This code is based on https://github.com/fohte/rubocop-daemon.
|
5
|
+
#
|
6
|
+
# Copyright (c) 2018 Hayato Kawai
|
7
|
+
#
|
8
|
+
# The MIT License (MIT)
|
9
|
+
#
|
10
|
+
# https://github.com/fohte/rubocop-daemon/blob/master/LICENSE.txt
|
11
|
+
#
|
12
|
+
module RuboCop
|
13
|
+
module Server
|
14
|
+
module ClientCommand
|
15
|
+
# This class is a client command to stop server process.
|
16
|
+
# @api private
|
17
|
+
class Stop < Base
|
18
|
+
def run
|
19
|
+
return unless check_running_server
|
20
|
+
|
21
|
+
pid = fork do
|
22
|
+
send_request(command: 'stop')
|
23
|
+
Server.wait_for_running_status!(false)
|
24
|
+
end
|
25
|
+
|
26
|
+
Process.waitpid(pid)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# This code is based on https://github.com/fohte/rubocop-daemon.
|
5
|
+
#
|
6
|
+
# Copyright (c) 2018 Hayato Kawai
|
7
|
+
#
|
8
|
+
# The MIT License (MIT)
|
9
|
+
#
|
10
|
+
# https://github.com/fohte/rubocop-daemon/blob/master/LICENSE.txt
|
11
|
+
#
|
12
|
+
module RuboCop
|
13
|
+
autoload :Version, 'rubocop/version'
|
14
|
+
|
15
|
+
module Server
|
16
|
+
# @api private
|
17
|
+
module ClientCommand
|
18
|
+
autoload :Base, 'rubocop/server/client_command/base'
|
19
|
+
autoload :Exec, 'rubocop/server/client_command/exec'
|
20
|
+
autoload :Restart, 'rubocop/server/client_command/restart'
|
21
|
+
autoload :Start, 'rubocop/server/client_command/start'
|
22
|
+
autoload :Status, 'rubocop/server/client_command/status'
|
23
|
+
autoload :Stop, 'rubocop/server/client_command/stop'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'socket'
|
4
|
+
require 'securerandom'
|
5
|
+
|
6
|
+
#
|
7
|
+
# This code is based on https://github.com/fohte/rubocop-daemon.
|
8
|
+
#
|
9
|
+
# Copyright (c) 2018 Hayato Kawai
|
10
|
+
#
|
11
|
+
# The MIT License (MIT)
|
12
|
+
#
|
13
|
+
# https://github.com/fohte/rubocop-daemon/blob/master/LICENSE.txt
|
14
|
+
#
|
15
|
+
module RuboCop
|
16
|
+
module Server
|
17
|
+
# The core of server process. It starts TCP server and perform socket communication.
|
18
|
+
# @api private
|
19
|
+
class Core
|
20
|
+
def self.token
|
21
|
+
@token ||= SecureRandom.hex(4)
|
22
|
+
end
|
23
|
+
|
24
|
+
def token
|
25
|
+
self.class.token
|
26
|
+
end
|
27
|
+
|
28
|
+
def start(host, port)
|
29
|
+
$PROGRAM_NAME = "rubocop --server #{Cache.project_dir}"
|
30
|
+
|
31
|
+
require 'rubocop'
|
32
|
+
start_server(host, port)
|
33
|
+
|
34
|
+
demonize if server_mode?
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def demonize
|
40
|
+
Cache.write_port_and_token_files(port: @server.addr[1], token: token)
|
41
|
+
|
42
|
+
pid = fork do
|
43
|
+
Process.daemon(true)
|
44
|
+
Cache.write_pid_file do
|
45
|
+
read_socket(@server.accept) until @server.closed?
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
Process.waitpid(pid)
|
50
|
+
end
|
51
|
+
|
52
|
+
def server_mode?
|
53
|
+
true
|
54
|
+
end
|
55
|
+
|
56
|
+
def start_server(host, port)
|
57
|
+
@server = TCPServer.open(host, port)
|
58
|
+
|
59
|
+
puts "RuboCop server starting on #{@server.addr[3]}:#{@server.addr[1]}."
|
60
|
+
end
|
61
|
+
|
62
|
+
def read_socket(socket)
|
63
|
+
SocketReader.new(socket).read!
|
64
|
+
rescue InvalidTokenError
|
65
|
+
socket.puts 'token is not valid.'
|
66
|
+
rescue ServerStopRequest
|
67
|
+
@server.close
|
68
|
+
rescue UnknownServerCommandError => e
|
69
|
+
socket.puts e.message
|
70
|
+
rescue Errno::EPIPE => e
|
71
|
+
warn e.inspect
|
72
|
+
rescue StandardError => e
|
73
|
+
socket.puts e.full_message
|
74
|
+
ensure
|
75
|
+
socket.close
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# This code is based on https://github.com/fohte/rubocop-daemon.
|
5
|
+
#
|
6
|
+
# Copyright (c) 2018 Hayato Kawai
|
7
|
+
#
|
8
|
+
# The MIT License (MIT)
|
9
|
+
#
|
10
|
+
# https://github.com/fohte/rubocop-daemon/blob/master/LICENSE.txt
|
11
|
+
#
|
12
|
+
module RuboCop
|
13
|
+
module Server
|
14
|
+
# @api private
|
15
|
+
class InvalidTokenError < StandardError; end
|
16
|
+
|
17
|
+
# @api private
|
18
|
+
class ServerStopRequest < StandardError; end
|
19
|
+
|
20
|
+
# @api private
|
21
|
+
class UnknownServerCommandError < StandardError; end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# This code is based on https://github.com/fohte/rubocop-daemon.
|
5
|
+
#
|
6
|
+
# Copyright (c) 2018 Hayato Kawai
|
7
|
+
#
|
8
|
+
# The MIT License (MIT)
|
9
|
+
#
|
10
|
+
# https://github.com/fohte/rubocop-daemon/blob/master/LICENSE.txt
|
11
|
+
#
|
12
|
+
module RuboCop
|
13
|
+
module Server
|
14
|
+
# This module has a helper memthod for `RuboCop::Server::SocketReader`.
|
15
|
+
# @api private
|
16
|
+
module Helper
|
17
|
+
def self.redirect(stdin: $stdin, stdout: $stdout, stderr: $stderr, &_block)
|
18
|
+
old_stdin = $stdin.dup
|
19
|
+
old_stdout = $stdout.dup
|
20
|
+
old_stderr = $stderr.dup
|
21
|
+
|
22
|
+
$stdin = stdin
|
23
|
+
$stdout = stdout
|
24
|
+
$stderr = stderr
|
25
|
+
|
26
|
+
yield
|
27
|
+
ensure
|
28
|
+
$stdin = old_stdin
|
29
|
+
$stdout = old_stdout
|
30
|
+
$stderr = old_stderr
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# This code is based on https://github.com/fohte/rubocop-daemon.
|
5
|
+
#
|
6
|
+
# Copyright (c) 2018 Hayato Kawai
|
7
|
+
#
|
8
|
+
# The MIT License (MIT)
|
9
|
+
#
|
10
|
+
# https://github.com/fohte/rubocop-daemon/blob/master/LICENSE.txt
|
11
|
+
#
|
12
|
+
module RuboCop
|
13
|
+
module Server
|
14
|
+
module ServerCommand
|
15
|
+
# Abstract base class for server command.
|
16
|
+
# @api private
|
17
|
+
class Base
|
18
|
+
# Common functionality for working with subclasses of this class.
|
19
|
+
# @api private
|
20
|
+
module Runner
|
21
|
+
def run
|
22
|
+
validate_token!
|
23
|
+
Dir.chdir(@cwd) do
|
24
|
+
super
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.inherited(child)
|
30
|
+
super
|
31
|
+
child.prepend Runner
|
32
|
+
end
|
33
|
+
|
34
|
+
def initialize(args, token: '', cwd: Dir.pwd)
|
35
|
+
@args = args
|
36
|
+
@token = token
|
37
|
+
@cwd = cwd
|
38
|
+
end
|
39
|
+
|
40
|
+
def run; end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def validate_token!
|
45
|
+
raise InvalidTokenError unless Cache.token_path.read == @token
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# This code is based on https://github.com/fohte/rubocop-daemon.
|
5
|
+
#
|
6
|
+
# Copyright (c) 2018 Hayato Kawai
|
7
|
+
#
|
8
|
+
# The MIT License (MIT)
|
9
|
+
#
|
10
|
+
# https://github.com/fohte/rubocop-daemon/blob/master/LICENSE.txt
|
11
|
+
#
|
12
|
+
module RuboCop
|
13
|
+
module Server
|
14
|
+
module ServerCommand
|
15
|
+
# This class is a server command to execute `rubocop` command using `RuboCop::CLI.new#run`.
|
16
|
+
# @api private
|
17
|
+
class Exec < Base
|
18
|
+
def run
|
19
|
+
Cache.status_path.delete if Cache.status_path.file?
|
20
|
+
# RuboCop output is colorized by default where there is a TTY.
|
21
|
+
# We must pass the --color option to preserve this behavior.
|
22
|
+
@args.unshift('--color') unless %w[--color --no-color].any? { |f| @args.include?(f) }
|
23
|
+
status = RuboCop::CLI.new.run(@args)
|
24
|
+
# This status file is read by `rubocop --server` (`RuboCop::Server::Clientcommand::Exec`).
|
25
|
+
# so that they use the correct exit code.
|
26
|
+
# Status is 1 when there are any issues, and 0 otherwise.
|
27
|
+
Cache.write_status_file(status)
|
28
|
+
rescue SystemExit
|
29
|
+
Cache.write_status_file(1)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# This code is based on https://github.com/fohte/rubocop-daemon.
|
5
|
+
#
|
6
|
+
# Copyright (c) 2018 Hayato Kawai
|
7
|
+
#
|
8
|
+
# The MIT License (MIT)
|
9
|
+
#
|
10
|
+
# https://github.com/fohte/rubocop-daemon/blob/master/LICENSE.txt
|
11
|
+
#
|
12
|
+
module RuboCop
|
13
|
+
module Server
|
14
|
+
module ServerCommand
|
15
|
+
# This class is a server command to stop server process.
|
16
|
+
# @api private
|
17
|
+
class Stop < Base
|
18
|
+
def run
|
19
|
+
raise ServerStopRequest
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# This code is based on https://github.com/fohte/rubocop-daemon.
|
5
|
+
#
|
6
|
+
# Copyright (c) 2018 Hayato Kawai
|
7
|
+
#
|
8
|
+
# The MIT License (MIT)
|
9
|
+
#
|
10
|
+
# https://github.com/fohte/rubocop-daemon/blob/master/LICENSE.txt
|
11
|
+
#
|
12
|
+
module RuboCop
|
13
|
+
module Server
|
14
|
+
# @api private
|
15
|
+
module ServerCommand
|
16
|
+
autoload :Base, 'rubocop/server/server_command/base'
|
17
|
+
autoload :Exec, 'rubocop/server/server_command/exec'
|
18
|
+
autoload :Stop, 'rubocop/server/server_command/stop'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# This code is based on https://github.com/fohte/rubocop-daemon.
|
5
|
+
#
|
6
|
+
# Copyright (c) 2018 Hayato Kawai
|
7
|
+
#
|
8
|
+
# The MIT License (MIT)
|
9
|
+
#
|
10
|
+
# https://github.com/fohte/rubocop-daemon/blob/master/LICENSE.txt
|
11
|
+
#
|
12
|
+
module RuboCop
|
13
|
+
module Server
|
14
|
+
# This class sends the request read from the socket to server.
|
15
|
+
# @api private
|
16
|
+
class SocketReader
|
17
|
+
Request = Struct.new(:header, :body)
|
18
|
+
Header = Struct.new(:token, :cwd, :command, :args)
|
19
|
+
|
20
|
+
def initialize(socket)
|
21
|
+
@socket = socket
|
22
|
+
end
|
23
|
+
|
24
|
+
def read!
|
25
|
+
request = parse_request(@socket.read)
|
26
|
+
|
27
|
+
Helper.redirect(
|
28
|
+
stdin: StringIO.new(request.body),
|
29
|
+
stdout: @socket,
|
30
|
+
stderr: @socket
|
31
|
+
) do
|
32
|
+
create_command_instance(request).run
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def parse_request(content)
|
39
|
+
raw_header, *body = content.lines
|
40
|
+
|
41
|
+
Request.new(parse_header(raw_header), body.join)
|
42
|
+
end
|
43
|
+
|
44
|
+
def parse_header(header)
|
45
|
+
token, cwd, command, *args = header.shellsplit
|
46
|
+
Header.new(token, cwd, command, args)
|
47
|
+
end
|
48
|
+
|
49
|
+
def create_command_instance(request)
|
50
|
+
klass = find_command_class(request.header.command)
|
51
|
+
|
52
|
+
klass.new(request.header.args, token: request.header.token, cwd: request.header.cwd)
|
53
|
+
end
|
54
|
+
|
55
|
+
def find_command_class(command)
|
56
|
+
case command
|
57
|
+
when 'stop' then ServerCommand::Stop
|
58
|
+
when 'exec' then ServerCommand::Exec
|
59
|
+
else
|
60
|
+
raise UnknownServerCommandError, "#{command.inspect} is not a valid command"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'platform'
|
4
|
+
|
5
|
+
#
|
6
|
+
# This code is based on https://github.com/fohte/rubocop-daemon.
|
7
|
+
#
|
8
|
+
# Copyright (c) 2018 Hayato Kawai
|
9
|
+
#
|
10
|
+
# The MIT License (MIT)
|
11
|
+
#
|
12
|
+
# https://github.com/fohte/rubocop-daemon/blob/master/LICENSE.txt
|
13
|
+
#
|
14
|
+
module RuboCop
|
15
|
+
# The bootstrap module for server.
|
16
|
+
# @api private
|
17
|
+
module Server
|
18
|
+
TIMEOUT = 20
|
19
|
+
|
20
|
+
autoload :CLI, 'rubocop/server/cli'
|
21
|
+
autoload :Cache, 'rubocop/server/cache'
|
22
|
+
autoload :ClientCommand, 'rubocop/server/client_command'
|
23
|
+
autoload :Helper, 'rubocop/server/helper'
|
24
|
+
autoload :Core, 'rubocop/server/core'
|
25
|
+
autoload :ServerCommand, 'rubocop/server/server_command'
|
26
|
+
autoload :SocketReader, 'rubocop/server/socket_reader'
|
27
|
+
|
28
|
+
class << self
|
29
|
+
def support_server?
|
30
|
+
RUBY_ENGINE == 'ruby' && !RuboCop::Platform.windows?
|
31
|
+
end
|
32
|
+
|
33
|
+
def running?
|
34
|
+
return false unless support_server? # Never running.
|
35
|
+
|
36
|
+
Cache.dir.exist? && Cache.pid_path.file? && Cache.pid_running?
|
37
|
+
end
|
38
|
+
|
39
|
+
def wait_for_running_status!(expected)
|
40
|
+
start_time = Time.now
|
41
|
+
while Server.running? != expected
|
42
|
+
sleep 0.1
|
43
|
+
next unless Time.now - start_time > TIMEOUT
|
44
|
+
|
45
|
+
warn "running? was not #{expected} after #{TIMEOUT} seconds!"
|
46
|
+
exit 1
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
require_relative 'server/errors'
|
data/lib/rubocop/version.rb
CHANGED
@@ -3,13 +3,15 @@
|
|
3
3
|
module RuboCop
|
4
4
|
# This module holds the RuboCop version information.
|
5
5
|
module Version
|
6
|
-
STRING = '1.
|
6
|
+
STRING = '1.31.2'
|
7
7
|
|
8
|
-
MSG = '%<version>s (using Parser %<parser_version>s, '\
|
8
|
+
MSG = '%<version>s (using Parser %<parser_version>s, ' \
|
9
9
|
'rubocop-ast %<rubocop_ast_version>s, ' \
|
10
10
|
'running on %<ruby_engine>s %<ruby_version>s %<ruby_platform>s)'
|
11
11
|
|
12
|
-
CANONICAL_FEATURE_NAMES = { 'Rspec' => 'RSpec'
|
12
|
+
CANONICAL_FEATURE_NAMES = { 'Rspec' => 'RSpec', 'Graphql' => 'GraphQL', 'Md' => 'Markdown',
|
13
|
+
'Thread_safety' => 'ThreadSafety' }.freeze
|
14
|
+
EXTENSION_PATH_NAMES = { 'rubocop-md' => 'markdown' }.freeze
|
13
15
|
|
14
16
|
# @api private
|
15
17
|
def self.version(debug: false, env: nil)
|
@@ -43,16 +45,21 @@ module RuboCop
|
|
43
45
|
features.map do |loaded_feature|
|
44
46
|
next unless (match = loaded_feature.match(/rubocop-(?<feature>.*)/))
|
45
47
|
|
46
|
-
|
48
|
+
# Get the expected name of the folder containing the extension code.
|
49
|
+
# Usually it would be the same as the extension name. but sometimes authors
|
50
|
+
# can choose slightly different name for their gems, e.g. rubocop-md instead of
|
51
|
+
# rubocop-markdown.
|
52
|
+
feature = EXTENSION_PATH_NAMES.fetch(loaded_feature, match[:feature])
|
53
|
+
|
47
54
|
begin
|
48
55
|
require "rubocop/#{feature}/version"
|
49
56
|
rescue LoadError
|
50
57
|
# Not worth mentioning libs that are not installed
|
51
|
-
else
|
52
|
-
next unless (feature_version = feature_version(feature))
|
53
|
-
|
54
|
-
" - #{loaded_feature} #{feature_version}"
|
55
58
|
end
|
59
|
+
|
60
|
+
next unless (feature_version = feature_version(feature))
|
61
|
+
|
62
|
+
" - #{loaded_feature} #{feature_version}"
|
56
63
|
end.compact
|
57
64
|
end
|
58
65
|
|
data/lib/rubocop.rb
CHANGED
@@ -63,7 +63,7 @@ require_relative 'rubocop/cop/mixin/alignment'
|
|
63
63
|
require_relative 'rubocop/cop/mixin/allowed_identifiers'
|
64
64
|
require_relative 'rubocop/cop/mixin/allowed_methods'
|
65
65
|
require_relative 'rubocop/cop/mixin/allowed_pattern'
|
66
|
-
require_relative 'rubocop/cop/mixin/auto_corrector'
|
66
|
+
require_relative 'rubocop/cop/mixin/auto_corrector' # rubocop:todo Naming/InclusiveLanguage
|
67
67
|
require_relative 'rubocop/cop/mixin/check_assignment'
|
68
68
|
require_relative 'rubocop/cop/mixin/check_line_breakable'
|
69
69
|
require_relative 'rubocop/cop/mixin/configurable_max'
|
@@ -72,7 +72,6 @@ require_relative 'rubocop/cop/mixin/configurable_enforced_style'
|
|
72
72
|
require_relative 'rubocop/cop/mixin/configurable_formatting'
|
73
73
|
require_relative 'rubocop/cop/mixin/configurable_naming'
|
74
74
|
require_relative 'rubocop/cop/mixin/configurable_numbering'
|
75
|
-
require_relative 'rubocop/cop/mixin/def_node'
|
76
75
|
require_relative 'rubocop/cop/mixin/documentation_comment'
|
77
76
|
require_relative 'rubocop/cop/mixin/duplication'
|
78
77
|
require_relative 'rubocop/cop/mixin/range_help'
|
@@ -130,6 +129,7 @@ require_relative 'rubocop/cop/mixin/uncommunicative_name'
|
|
130
129
|
require_relative 'rubocop/cop/mixin/unused_argument'
|
131
130
|
require_relative 'rubocop/cop/mixin/visibility_help'
|
132
131
|
require_relative 'rubocop/cop/mixin/comments_help' # relies on visibility_help
|
132
|
+
require_relative 'rubocop/cop/mixin/def_node' # relies on visibility_help
|
133
133
|
|
134
134
|
require_relative 'rubocop/cop/utils/format_string'
|
135
135
|
|
@@ -160,7 +160,6 @@ require_relative 'rubocop/cop/bundler/gem_version'
|
|
160
160
|
require_relative 'rubocop/cop/bundler/insecure_protocol_source'
|
161
161
|
require_relative 'rubocop/cop/bundler/ordered_gems'
|
162
162
|
|
163
|
-
require_relative 'rubocop/cop/gemspec/date_assignment'
|
164
163
|
require_relative 'rubocop/cop/gemspec/dependency_version'
|
165
164
|
require_relative 'rubocop/cop/gemspec/deprecated_attribute_assignment'
|
166
165
|
require_relative 'rubocop/cop/gemspec/duplicated_assignment'
|
@@ -220,6 +219,8 @@ require_relative 'rubocop/cop/layout/indentation_width'
|
|
220
219
|
require_relative 'rubocop/cop/layout/initial_indentation'
|
221
220
|
require_relative 'rubocop/cop/layout/leading_comment_space'
|
222
221
|
require_relative 'rubocop/cop/layout/leading_empty_lines'
|
222
|
+
require_relative 'rubocop/cop/layout/line_continuation_leading_space'
|
223
|
+
require_relative 'rubocop/cop/layout/line_continuation_spacing'
|
223
224
|
require_relative 'rubocop/cop/layout/line_end_string_concatenation_indentation'
|
224
225
|
require_relative 'rubocop/cop/layout/line_length'
|
225
226
|
require_relative 'rubocop/cop/layout/multiline_array_brace_layout'
|
@@ -278,6 +279,7 @@ require_relative 'rubocop/cop/lint/binary_operator_with_identical_operands'
|
|
278
279
|
require_relative 'rubocop/cop/lint/boolean_symbol'
|
279
280
|
require_relative 'rubocop/cop/lint/circular_argument_reference'
|
280
281
|
require_relative 'rubocop/cop/lint/constant_definition_in_block'
|
282
|
+
require_relative 'rubocop/cop/lint/constant_overwritten_in_rescue'
|
281
283
|
require_relative 'rubocop/cop/lint/constant_resolution'
|
282
284
|
require_relative 'rubocop/cop/lint/debugger'
|
283
285
|
require_relative 'rubocop/cop/lint/deprecated_class_methods'
|
@@ -329,6 +331,7 @@ require_relative 'rubocop/cop/lint/nested_method_definition'
|
|
329
331
|
require_relative 'rubocop/cop/lint/nested_percent_literal'
|
330
332
|
require_relative 'rubocop/cop/lint/next_without_accumulator'
|
331
333
|
require_relative 'rubocop/cop/lint/no_return_in_begin_end_blocks'
|
334
|
+
require_relative 'rubocop/cop/lint/non_atomic_file_operation'
|
332
335
|
require_relative 'rubocop/cop/lint/non_deterministic_require_order'
|
333
336
|
require_relative 'rubocop/cop/lint/non_local_exit_from_iterator'
|
334
337
|
require_relative 'rubocop/cop/lint/number_conversion'
|
@@ -387,6 +390,7 @@ require_relative 'rubocop/cop/lint/uri_escape_unescape'
|
|
387
390
|
require_relative 'rubocop/cop/lint/uri_regexp'
|
388
391
|
require_relative 'rubocop/cop/lint/useless_access_modifier'
|
389
392
|
require_relative 'rubocop/cop/lint/useless_assignment'
|
393
|
+
require_relative 'rubocop/cop/lint/useless_else_without_rescue'
|
390
394
|
require_relative 'rubocop/cop/lint/useless_method_definition'
|
391
395
|
require_relative 'rubocop/cop/lint/useless_ruby2_keywords'
|
392
396
|
require_relative 'rubocop/cop/lint/useless_setter_call'
|
@@ -665,30 +669,7 @@ require_relative 'rubocop/cop/security/open'
|
|
665
669
|
require_relative 'rubocop/cop/security/yaml_load'
|
666
670
|
|
667
671
|
require_relative 'rubocop/cop/team'
|
668
|
-
|
669
|
-
require_relative 'rubocop/formatter/base_formatter'
|
670
|
-
require_relative 'rubocop/formatter/simple_text_formatter'
|
671
|
-
# relies on simple text
|
672
|
-
require_relative 'rubocop/formatter/clang_style_formatter'
|
673
|
-
require_relative 'rubocop/formatter/disabled_config_formatter'
|
674
|
-
require_relative 'rubocop/formatter/emacs_style_formatter'
|
675
|
-
require_relative 'rubocop/formatter/file_list_formatter'
|
676
|
-
require_relative 'rubocop/formatter/fuubar_style_formatter'
|
677
|
-
require_relative 'rubocop/formatter/git_hub_actions_formatter'
|
678
|
-
require_relative 'rubocop/formatter/html_formatter'
|
679
|
-
require_relative 'rubocop/formatter/json_formatter'
|
680
|
-
require_relative 'rubocop/formatter/junit_formatter'
|
681
|
-
require_relative 'rubocop/formatter/markdown_formatter'
|
682
|
-
require_relative 'rubocop/formatter/offense_count_formatter'
|
683
|
-
require_relative 'rubocop/formatter/progress_formatter'
|
684
|
-
require_relative 'rubocop/formatter/quiet_formatter'
|
685
|
-
require_relative 'rubocop/formatter/tap_formatter'
|
686
|
-
require_relative 'rubocop/formatter/worst_offenders_formatter'
|
687
|
-
require_relative 'rubocop/formatter/pacman_formatter'
|
688
|
-
# relies on progress formatter
|
689
|
-
require_relative 'rubocop/formatter/auto_gen_config_formatter'
|
690
|
-
|
691
|
-
require_relative 'rubocop/formatter/formatter_set'
|
672
|
+
require_relative 'rubocop/formatter'
|
692
673
|
|
693
674
|
require_relative 'rubocop/cached_data'
|
694
675
|
require_relative 'rubocop/config'
|