rubocop-daemon 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +36 -0
- data/.rspec +3 -0
- data/.rubocop.yml +26 -0
- data/.travis.yml +5 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +21 -0
- data/README.md +73 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/exe/rubocop-daemon +8 -0
- data/lib/rubocop/daemon/cache.rb +36 -0
- data/lib/rubocop/daemon/cli.rb +56 -0
- data/lib/rubocop/daemon/client_command/base.rb +34 -0
- data/lib/rubocop/daemon/client_command/exec.rb +27 -0
- data/lib/rubocop/daemon/client_command/restart.rb +26 -0
- data/lib/rubocop/daemon/client_command/start.rb +24 -0
- data/lib/rubocop/daemon/client_command/status.rb +27 -0
- data/lib/rubocop/daemon/client_command/stop.rb +23 -0
- data/lib/rubocop/daemon/client_command.rb +14 -0
- data/lib/rubocop/daemon/errors.rb +11 -0
- data/lib/rubocop/daemon/helper.rb +23 -0
- data/lib/rubocop/daemon/server.rb +49 -0
- data/lib/rubocop/daemon/server_command/base.rb +36 -0
- data/lib/rubocop/daemon/server_command/exec.rb +14 -0
- data/lib/rubocop/daemon/server_command/stop.rb +13 -0
- data/lib/rubocop/daemon/server_command.rb +11 -0
- data/lib/rubocop/daemon/socket_reader.rb +57 -0
- data/lib/rubocop/daemon/version.rb +7 -0
- data/lib/rubocop/daemon.rb +21 -0
- data/rubocop-daemon.gemspec +30 -0
- metadata +132 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c5579693de992c601188ad58c5ea7e3e5988ac40e6b3d2344000e454ae48f566
|
4
|
+
data.tar.gz: b2e0ffca2fa243fe6bfc687b1710871317f9e358850ea4ebe7c42903f885372b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a992d260d61f322ce081554e10e64330cc01e3ec868134da73a8c2c5fa79f472470b4de54b122399cd5db7812d37f2ee4c0b5b6be6d86e260f42b5366b15e5de
|
7
|
+
data.tar.gz: 555be81d6ae5c2a6b8b0e0b465caaffdb227faa769e9214165d1d616799d81f17ec1993aca274475179bb1f177622728254da219ccb820c9ee28662e8402d092
|
data/.gitignore
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
## Specific to RubyMotion:
|
14
|
+
.dat*
|
15
|
+
.repl_history
|
16
|
+
build/
|
17
|
+
*.bridgesupport
|
18
|
+
build-iPhoneOS/
|
19
|
+
build-iPhoneSimulator/
|
20
|
+
|
21
|
+
## Documentation cache and generated files:
|
22
|
+
/.yardoc/
|
23
|
+
/_yardoc/
|
24
|
+
/doc/
|
25
|
+
/rdoc/
|
26
|
+
|
27
|
+
## Environment normalization:
|
28
|
+
/.bundle/
|
29
|
+
/vendor/bundle
|
30
|
+
/lib/bundler/man/
|
31
|
+
|
32
|
+
Gemfile.lock
|
33
|
+
.ruby-version
|
34
|
+
.ruby-gemset
|
35
|
+
|
36
|
+
.rvmrc
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.1
|
3
|
+
|
4
|
+
Style/FrozenStringLiteralComment:
|
5
|
+
EnforcedStyle: always
|
6
|
+
|
7
|
+
Layout/EndOfLine:
|
8
|
+
EnforcedStyle: lf
|
9
|
+
|
10
|
+
Style/TrailingCommaInArguments:
|
11
|
+
EnforcedStyleForMultiline: consistent_comma
|
12
|
+
|
13
|
+
Style/TrailingCommaInArrayLiteral:
|
14
|
+
EnforcedStyleForMultiline: consistent_comma
|
15
|
+
|
16
|
+
Style/TrailingCommaInHashLiteral:
|
17
|
+
EnforcedStyleForMultiline: consistent_comma
|
18
|
+
|
19
|
+
Metrics/LineLength:
|
20
|
+
Max: 120
|
21
|
+
|
22
|
+
Metrics/MethodLength:
|
23
|
+
Enabled: false
|
24
|
+
|
25
|
+
Style/Documentation:
|
26
|
+
Enabled: false
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Hayato Kawai
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
# rubocop-daemon
|
2
|
+
|
3
|
+
`rubocop-daemon` makes RuboCop faster.
|
4
|
+
|
5
|
+
**This tool is beta version.**
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
`rubocop-daemon` is not released on rubygems.org yet, but you can try `rubocop-daemon`:
|
10
|
+
|
11
|
+
```sh
|
12
|
+
git clone https://github.com/fohte/rubocop-daemon.git && cd rubocop-daemon
|
13
|
+
bundle install
|
14
|
+
bundle exec rake install
|
15
|
+
```
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
To start the server, just run:
|
20
|
+
|
21
|
+
```sh
|
22
|
+
rubocop-daemon start
|
23
|
+
```
|
24
|
+
|
25
|
+
Then you can execute RuboCop fast:
|
26
|
+
|
27
|
+
```sh
|
28
|
+
rubocop-daemon exec
|
29
|
+
```
|
30
|
+
|
31
|
+
And you can pass files:
|
32
|
+
|
33
|
+
```sh
|
34
|
+
rubocop-daemon exec foo.rb bar.rb
|
35
|
+
```
|
36
|
+
|
37
|
+
If you want to pass arguments to RuboCop, you should separate arguments by `--`:
|
38
|
+
|
39
|
+
```sh
|
40
|
+
rubocop-daemon exec -- --auto-correct
|
41
|
+
```
|
42
|
+
|
43
|
+
## Commands
|
44
|
+
|
45
|
+
You can control the server like this:
|
46
|
+
|
47
|
+
```
|
48
|
+
rubocop-daemon <command>
|
49
|
+
```
|
50
|
+
|
51
|
+
Available commands:
|
52
|
+
|
53
|
+
* `start`: start the server
|
54
|
+
* `stop`: stop the server
|
55
|
+
* `status`: print out whether the server is currently running
|
56
|
+
* `restart`: restart the server
|
57
|
+
* `exec [file1, file2, ...] [-- [rubocop-options]]`: invoke `rubocop` with the given `rubocop-options`
|
58
|
+
|
59
|
+
## More speed
|
60
|
+
|
61
|
+
If you're really into performance and want the lowest possible latency, talk to the `rubocop-daemon` server with netcat:
|
62
|
+
|
63
|
+
```sh
|
64
|
+
echo "$(cat ~/.cache/rubocop-daemon/token) $PWD exec [rubocop-options]" | nc localhost $(cat ~/.cache/rubocop-daemon/port)
|
65
|
+
```
|
66
|
+
|
67
|
+
## Contributing
|
68
|
+
|
69
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/fohte/rubocop-daemon.
|
70
|
+
|
71
|
+
## License
|
72
|
+
|
73
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'rubocop/daemon'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/exe/rubocop-daemon
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'pathname'
|
4
|
+
|
5
|
+
module RuboCop
|
6
|
+
module Daemon
|
7
|
+
class Cache
|
8
|
+
def self.dir
|
9
|
+
Pathname.new(File.expand_path('~/.cache/rubocop-daemon')).tap do |d|
|
10
|
+
d.mkdir unless d.exist?
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.port_path
|
15
|
+
dir.join('port')
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.token_path
|
19
|
+
dir.join('token')
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.pid_path
|
23
|
+
dir.join('pid')
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.make_server_file(port:, token:)
|
27
|
+
port_path.write(port)
|
28
|
+
token_path.write(token)
|
29
|
+
pid_path.write(Process.pid)
|
30
|
+
yield
|
31
|
+
ensure
|
32
|
+
dir.rmtree
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
|
5
|
+
module RuboCop
|
6
|
+
module Daemon
|
7
|
+
class CLI
|
8
|
+
def self.new_parser(&_block)
|
9
|
+
OptionParser.new do |opts|
|
10
|
+
opts.version = VERSION
|
11
|
+
yield(opts)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def run(argv = ARGV)
|
16
|
+
parser.order!(argv)
|
17
|
+
return if argv.empty?
|
18
|
+
create_subcommand_instance(argv)
|
19
|
+
rescue OptionParser::InvalidOption => e
|
20
|
+
warn "error: #{e.message}"
|
21
|
+
exit 1
|
22
|
+
rescue UnknownClientCommandError => e
|
23
|
+
warn "rubocop-daemon: #{e.message}. See 'rubocop-daemon --help'."
|
24
|
+
exit 1
|
25
|
+
rescue ServerIsNotRunningError
|
26
|
+
warn 'rubocop-daemon: server is not running.'
|
27
|
+
exit 1
|
28
|
+
end
|
29
|
+
|
30
|
+
def parser
|
31
|
+
@parser ||= self.class.new_parser do |opts|
|
32
|
+
opts.banner = 'usage: rubocop-daemon <command> [<args>]'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def create_subcommand_instance(argv)
|
39
|
+
subcommand, *args = argv
|
40
|
+
find_subcommand_class(subcommand).new(args).run
|
41
|
+
end
|
42
|
+
|
43
|
+
def find_subcommand_class(subcommand)
|
44
|
+
case subcommand
|
45
|
+
when 'exec' then ClientCommand::Exec
|
46
|
+
when 'restart' then ClientCommand::Restart
|
47
|
+
when 'start' then ClientCommand::Start
|
48
|
+
when 'status' then ClientCommand::Status
|
49
|
+
when 'stop' then ClientCommand::Stop
|
50
|
+
else
|
51
|
+
raise UnknownClientCommandError, "#{subcommand.inspect} is not a rubocop-daemon command"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'shellwords'
|
4
|
+
require 'socket'
|
5
|
+
|
6
|
+
module RuboCop
|
7
|
+
module Daemon
|
8
|
+
module ClientCommand
|
9
|
+
class Base
|
10
|
+
def initialize(argv)
|
11
|
+
@argv = argv.dup
|
12
|
+
@options = {}
|
13
|
+
end
|
14
|
+
|
15
|
+
def run; end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def send_request(command:, args: [], body: '')
|
20
|
+
TCPSocket.open('127.0.0.1', Cache.port_path.read) do |socket|
|
21
|
+
socket.puts [Cache.token_path.read, Dir.pwd, command, *args].shelljoin
|
22
|
+
socket.write body
|
23
|
+
socket.close_write
|
24
|
+
STDOUT.write socket.read(4096) until socket.eof?
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def check_running_server!
|
29
|
+
raise ServerIsNotRunningError unless Daemon.running?
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Daemon
|
5
|
+
module ClientCommand
|
6
|
+
class Exec < Base
|
7
|
+
def run
|
8
|
+
args = parser.parse(@argv)
|
9
|
+
check_running_server!
|
10
|
+
send_request(
|
11
|
+
command: 'exec',
|
12
|
+
args: args,
|
13
|
+
body: $stdin.tty? ? '' : $stdin.read,
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def parser
|
20
|
+
@parser ||= CLI.new_parser do |p|
|
21
|
+
p.banner = 'usage: rubocop-daemon exec [options] [files...] [-- [rubocop-options]]'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Daemon
|
5
|
+
module ClientCommand
|
6
|
+
class Restart < Base
|
7
|
+
def run
|
8
|
+
parser.parse(@argv)
|
9
|
+
check_running_server!
|
10
|
+
send_request(command: 'stop')
|
11
|
+
Server.new.start(@options.fetch(:port, 0))
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def parser
|
17
|
+
@parser ||= CLI.new_parser do |p|
|
18
|
+
p.banner = 'usage: rubocop-daemon restart'
|
19
|
+
|
20
|
+
p.on('-p', '--port [PORT]') { |v| @options[:port] = v }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Daemon
|
5
|
+
module ClientCommand
|
6
|
+
class Start < Base
|
7
|
+
def run
|
8
|
+
parser.parse(@argv)
|
9
|
+
Server.new.start(@options.fetch(:port, 0))
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def parser
|
15
|
+
@parser ||= CLI.new_parser do |p|
|
16
|
+
p.banner = 'usage: rubocop-daemon start [options]'
|
17
|
+
|
18
|
+
p.on('-p', '--port [PORT]') { |v| @options[:port] = v }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Daemon
|
5
|
+
module ClientCommand
|
6
|
+
class Status < Base
|
7
|
+
def run
|
8
|
+
parser.parse(@argv)
|
9
|
+
|
10
|
+
if Daemon.running?
|
11
|
+
puts 'rubocop-daemon is running.'
|
12
|
+
else
|
13
|
+
puts 'rubocop-daemon is not running.'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def parser
|
20
|
+
@parser ||= CLI.new_parser do |p|
|
21
|
+
p.banner = 'usage: rubocop-daemon status'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Daemon
|
5
|
+
module ClientCommand
|
6
|
+
class Stop < Base
|
7
|
+
def run
|
8
|
+
parser.parse(@argv)
|
9
|
+
check_running_server!
|
10
|
+
send_request(command: 'stop')
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def parser
|
16
|
+
@parser ||= CLI.new_parser do |p|
|
17
|
+
p.banner = 'usage: rubocop-daemon stop'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Daemon
|
5
|
+
module ClientCommand
|
6
|
+
autoload :Base, 'rubocop/daemon/client_command/base'
|
7
|
+
autoload :Exec, 'rubocop/daemon/client_command/exec'
|
8
|
+
autoload :Restart, 'rubocop/daemon/client_command/restart'
|
9
|
+
autoload :Start, 'rubocop/daemon/client_command/start'
|
10
|
+
autoload :Status, 'rubocop/daemon/client_command/status'
|
11
|
+
autoload :Stop, 'rubocop/daemon/client_command/stop'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Daemon
|
5
|
+
class InvalidTokenError < StandardError; end
|
6
|
+
class ServerIsNotRunningError < StandardError; end
|
7
|
+
class ServerStopRequest < StandardError; end
|
8
|
+
class UnknownClientCommandError < StandardError; end
|
9
|
+
class UnknownServerCommandError < StandardError; end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Daemon
|
5
|
+
module Helper
|
6
|
+
def self.redirect(stdin: $stdin, stdout: $stdout, stderr: $stderr, &_block)
|
7
|
+
old_stdin = $stdin.dup
|
8
|
+
old_stdout = $stdout.dup
|
9
|
+
old_stderr = $stderr.dup
|
10
|
+
|
11
|
+
$stdin = stdin
|
12
|
+
$stdout = stdout
|
13
|
+
$stderr = stderr
|
14
|
+
|
15
|
+
yield
|
16
|
+
ensure
|
17
|
+
$stdin = old_stdin
|
18
|
+
$stdout = old_stdout
|
19
|
+
$stderr = old_stderr
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'socket'
|
4
|
+
require 'shellwords'
|
5
|
+
require 'securerandom'
|
6
|
+
|
7
|
+
module RuboCop
|
8
|
+
module Daemon
|
9
|
+
class Server
|
10
|
+
def self.token
|
11
|
+
@token ||= SecureRandom.hex(4)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.start(port)
|
15
|
+
new.start(port)
|
16
|
+
end
|
17
|
+
|
18
|
+
def token
|
19
|
+
self.class.token
|
20
|
+
end
|
21
|
+
|
22
|
+
def start(port)
|
23
|
+
require 'rubocop'
|
24
|
+
@server = TCPServer.open('127.0.0.1', port)
|
25
|
+
|
26
|
+
Cache.make_server_file(port: @server.addr[1], token: token) do
|
27
|
+
Process.daemon(true)
|
28
|
+
read_socket(@server.accept) until @server.closed?
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def read_socket(socket)
|
35
|
+
SocketReader.new(socket).read!
|
36
|
+
rescue InvalidTokenError
|
37
|
+
socket.puts 'token is not valid.'
|
38
|
+
rescue ServerStopRequest
|
39
|
+
@server.close
|
40
|
+
rescue UnknownServerCommandError => e
|
41
|
+
socket.puts e.message
|
42
|
+
rescue StandardError => e
|
43
|
+
socket.puts e.full_message
|
44
|
+
ensure
|
45
|
+
socket.close
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Daemon
|
5
|
+
module ServerCommand
|
6
|
+
class Base
|
7
|
+
module Runner
|
8
|
+
def run
|
9
|
+
validate_token!
|
10
|
+
Dir.chdir(@cwd) do
|
11
|
+
super
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.inherited(child)
|
17
|
+
child.prepend Runner
|
18
|
+
end
|
19
|
+
|
20
|
+
def initialize(args, token: '', cwd: Dir.pwd)
|
21
|
+
@args = args
|
22
|
+
@token = token
|
23
|
+
@cwd = cwd
|
24
|
+
end
|
25
|
+
|
26
|
+
def run; end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def validate_token!
|
31
|
+
raise InvalidTokenError unless Cache.token_path.read == @token
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Daemon
|
5
|
+
module ServerCommand
|
6
|
+
autoload :Base, 'rubocop/daemon/server_command/base'
|
7
|
+
autoload :Exec, 'rubocop/daemon/server_command/exec'
|
8
|
+
autoload :Stop, 'rubocop/daemon/server_command/stop'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Daemon
|
5
|
+
class SocketReader
|
6
|
+
Request = Struct.new(:header, :body)
|
7
|
+
Header = Struct.new(:token, :cwd, :command, :args)
|
8
|
+
|
9
|
+
def initialize(socket)
|
10
|
+
@socket = socket
|
11
|
+
end
|
12
|
+
|
13
|
+
def read!
|
14
|
+
request = parse_request(@socket.read)
|
15
|
+
|
16
|
+
Helper.redirect(
|
17
|
+
stdin: StringIO.new(request.body),
|
18
|
+
stdout: @socket,
|
19
|
+
stderr: @socket,
|
20
|
+
) do
|
21
|
+
create_command_instance(request).run
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def parse_request(content)
|
28
|
+
raw_header, *body = content.lines
|
29
|
+
Request.new(parse_header(raw_header), body.join)
|
30
|
+
end
|
31
|
+
|
32
|
+
def parse_header(header)
|
33
|
+
token, cwd, command, *args = header.shellsplit
|
34
|
+
Header.new(token, cwd, command, args)
|
35
|
+
end
|
36
|
+
|
37
|
+
def create_command_instance(request)
|
38
|
+
klass = find_command_class(request.header.command)
|
39
|
+
|
40
|
+
klass.new(
|
41
|
+
request.header.args,
|
42
|
+
token: request.header.token,
|
43
|
+
cwd: request.header.cwd,
|
44
|
+
)
|
45
|
+
end
|
46
|
+
|
47
|
+
def find_command_class(command)
|
48
|
+
case command
|
49
|
+
when 'stop' then ServerCommand::Stop
|
50
|
+
when 'exec' then ServerCommand::Exec
|
51
|
+
else
|
52
|
+
raise UnknownServerCommandError, "#{command.inspect} is not a valid command"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Daemon
|
5
|
+
autoload :VERSION, 'rubocop/daemon/version'
|
6
|
+
|
7
|
+
autoload :CLI, 'rubocop/daemon/cli'
|
8
|
+
autoload :Cache, 'rubocop/daemon/cache'
|
9
|
+
autoload :ClientCommand, 'rubocop/daemon/client_command'
|
10
|
+
autoload :Helper, 'rubocop/daemon/helper'
|
11
|
+
autoload :Server, 'rubocop/daemon/server'
|
12
|
+
autoload :ServerCommand, 'rubocop/daemon/server_command'
|
13
|
+
autoload :SocketReader, 'rubocop/daemon/socket_reader'
|
14
|
+
|
15
|
+
def self.running?
|
16
|
+
Cache.dir.exist?
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'rubocop/daemon/errors'
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'rubocop/daemon/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'rubocop-daemon'
|
9
|
+
spec.version = RuboCop::Daemon::VERSION
|
10
|
+
spec.authors = ['Hayato Kawai']
|
11
|
+
spec.email = ['fohte.hk@gmail.com']
|
12
|
+
|
13
|
+
spec.summary = 'Makes RuboCop faster'
|
14
|
+
spec.description = 'rubocop-daemon is a CLI tool that makes RuboCop faster.'
|
15
|
+
spec.homepage = 'https://github.com/fohte/rubocop-daemon'
|
16
|
+
spec.license = 'MIT'
|
17
|
+
|
18
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
19
|
+
f.match(%r{^(test|spec|features)/})
|
20
|
+
end
|
21
|
+
spec.bindir = 'exe'
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ['lib']
|
24
|
+
|
25
|
+
spec.add_dependency 'rubocop'
|
26
|
+
|
27
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
28
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
29
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rubocop-daemon
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Hayato Kawai
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-04-04 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'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
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.16'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.16'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
description: rubocop-daemon is a CLI tool that makes RuboCop faster.
|
70
|
+
email:
|
71
|
+
- fohte.hk@gmail.com
|
72
|
+
executables:
|
73
|
+
- rubocop-daemon
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- ".rspec"
|
79
|
+
- ".rubocop.yml"
|
80
|
+
- ".travis.yml"
|
81
|
+
- Gemfile
|
82
|
+
- LICENSE.txt
|
83
|
+
- README.md
|
84
|
+
- Rakefile
|
85
|
+
- bin/console
|
86
|
+
- bin/setup
|
87
|
+
- exe/rubocop-daemon
|
88
|
+
- lib/rubocop/daemon.rb
|
89
|
+
- lib/rubocop/daemon/cache.rb
|
90
|
+
- lib/rubocop/daemon/cli.rb
|
91
|
+
- lib/rubocop/daemon/client_command.rb
|
92
|
+
- lib/rubocop/daemon/client_command/base.rb
|
93
|
+
- lib/rubocop/daemon/client_command/exec.rb
|
94
|
+
- lib/rubocop/daemon/client_command/restart.rb
|
95
|
+
- lib/rubocop/daemon/client_command/start.rb
|
96
|
+
- lib/rubocop/daemon/client_command/status.rb
|
97
|
+
- lib/rubocop/daemon/client_command/stop.rb
|
98
|
+
- lib/rubocop/daemon/errors.rb
|
99
|
+
- lib/rubocop/daemon/helper.rb
|
100
|
+
- lib/rubocop/daemon/server.rb
|
101
|
+
- lib/rubocop/daemon/server_command.rb
|
102
|
+
- lib/rubocop/daemon/server_command/base.rb
|
103
|
+
- lib/rubocop/daemon/server_command/exec.rb
|
104
|
+
- lib/rubocop/daemon/server_command/stop.rb
|
105
|
+
- lib/rubocop/daemon/socket_reader.rb
|
106
|
+
- lib/rubocop/daemon/version.rb
|
107
|
+
- rubocop-daemon.gemspec
|
108
|
+
homepage: https://github.com/fohte/rubocop-daemon
|
109
|
+
licenses:
|
110
|
+
- MIT
|
111
|
+
metadata: {}
|
112
|
+
post_install_message:
|
113
|
+
rdoc_options: []
|
114
|
+
require_paths:
|
115
|
+
- lib
|
116
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
requirements: []
|
127
|
+
rubyforge_project:
|
128
|
+
rubygems_version: 2.7.3
|
129
|
+
signing_key:
|
130
|
+
specification_version: 4
|
131
|
+
summary: Makes RuboCop faster
|
132
|
+
test_files: []
|