rubocop-daemon 0.3.1 → 0.3.2

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: e34a73d9ee5a5f38b2a531efc3a19103b93ae9eef54faea95751820815c893b4
4
- data.tar.gz: 9968fd324e630f5ad2d40f9c9895d4dec8a03e016087ba3b95978a126ee045ab
3
+ metadata.gz: 190e538beeb1f58fc133eda7baff54f976c4835d14143d6ca7bb8780e15f88c1
4
+ data.tar.gz: 31f5094c298bc1af68a853990a8deb9aa39a5fabcc1de609403edea2081745fb
5
5
  SHA512:
6
- metadata.gz: 03b61796952aa7762a0a4ecb967e6f0d3da0ad54c45395789255cbd188646d8662f0a2f31a8fd82b7fcfaad184fbed69df641c64ea5904bd7ffaa5d454fb36cf
7
- data.tar.gz: e1dd9d6eccb027a1f4ddc3316fa488d69983108d5381348f0397ab8f01aa5b270846c3fec43cadeab28e5d5e93e5fd8f56d178c8dd6c3d48390c2228336084bb
6
+ metadata.gz: 6c8c1f9fe127c33de58c83a7e4bd0e283356432202aef18613476a5f597971139c00cfc6dc0de1814e886a3365f37cabc7558425429f0d15af4fb2268b482d4c
7
+ data.tar.gz: ec698adacaca218f38d95c4cb91ef0fd25dd8a2c35de20b2b2703cbd8282b8419760a1c44fd0e0cc53f34af2f889efafbc5b36b194ddaac5fd1408eb5a9db5c5
data/README.md CHANGED
@@ -12,6 +12,12 @@ Install `rubocop-daemon` via rubygems.org:
12
12
  gem install rubocop-daemon
13
13
  ```
14
14
 
15
+ or if you install RuboCop using bundler, put this in your `Gemfile`:
16
+
17
+ ```ruby
18
+ gem 'rubocop-daemon', require: false
19
+ ```
20
+
15
21
  ## Usage
16
22
 
17
23
  To start the server, just run:
@@ -76,7 +82,17 @@ rubocop-daemon-wrapper foo.rb bar.rb
76
82
 
77
83
  `rubocop-daemon-wrapper` will automatically start the daemon server if it is not already running. So the first call will be about the same as `rubocop`, but the second call will be much faster.
78
84
 
79
- ## Use with VS Code
85
+ ### Use with Bundler
86
+
87
+ If you install `rubocop-daemon` with bundler, you should set `RUBOCOP_DAEMON_USE_BUNDLER` environment variable:
88
+
89
+ ```console
90
+ $ export RUBOCOP_DAEMON_USE_BUNDLER=true
91
+ ```
92
+
93
+ Now `rubocop-daemon-wrapper` will call the `rubocop-daemon` command with `bundle exec`.
94
+
95
+ ### Use with VS Code
80
96
 
81
97
  Unfortunately, the [vscode-ruby extension doesn't really allow you to customize the `rubocop` path or binary](https://github.com/rubyide/vscode-ruby/issues/413). (You can change the linter path, but not the formatter.)
82
98
 
@@ -85,14 +101,46 @@ In the meantime, you could just override the `rubocop` binary with a symlink to
85
101
  ```bash
86
102
  # Find your rubocop path
87
103
  $ which rubocop
88
- # => /Users/username/.rvm/gems/ruby-2.5.3/bin/rubocop
104
+ <HOME>/.rvm/gems/ruby-x.y.z/bin/rubocop
105
+
106
+ # Override rubocop with a symlink to rubocop-daemon-wrapper
107
+ $ ln -fs /usr/local/bin/rubocop-daemon-wrapper $HOME/.rvm/gems/ruby-x.y.z/bin/rubocop
108
+ ```
109
+
110
+ Or, if you use rbenv:
111
+
112
+ ```bash
113
+ # which rubocop is rbenv running?
114
+ $ rbenv which rubocop
115
+ <HOME>/.rbenv/versions/x.y.z/bin/rubocop
89
116
 
90
117
  # Override rubocop with a symlink to rubocop-daemon-wrapper
91
- $ ln -fs /usr/local/bin/rubocop-daemon-wrapper /Users/username/.rvm/gems/ruby-2.5.3/bin/rubocop
118
+ $ ln -fs /usr/local/bin/rubocop-daemon-wrapper $HOME/.rbenv/versions/x.y.z/bin/rubocop
92
119
  ```
93
120
 
94
121
  Now VS Code will use the `rubocop-daemon-wrapper` script, and `formatOnSave` should be much faster (~150ms instead of 3-5 seconds).
95
122
 
123
+ ### Use with Neovim/Vim8 and ALE
124
+
125
+ [ALE](https://github.com/w0rp/ale) setting example:
126
+
127
+ ```vim
128
+ " Use `rubocop-daemon-wrapper` instead of `rubocop`
129
+ let g:ale_ruby_rubocop_executable = 'rubocop-daemon-wrapper'
130
+ ```
131
+
132
+ Auto-correct on save setting example:
133
+
134
+ ```vim
135
+ " optional: Set fixer(not only linter).
136
+ let g:ale_fixers = {
137
+ \ 'ruby': ['rubocop'],
138
+ \}
139
+
140
+ " optional: Auto-correct on save.
141
+ let g:ale_fix_on_save = 1
142
+ ```
143
+
96
144
  ## Contributing
97
145
 
98
146
  Bug reports and pull requests are welcome on GitHub at https://github.com/fohte/rubocop-daemon.
@@ -1,8 +1,24 @@
1
1
  #!/bin/bash
2
+
2
3
  set -e
3
4
 
5
+ COMMAND_PREFIX=""
6
+
7
+ if [ -n "$RUBOCOP_DAEMON_USE_BUNDLER" ]; then
8
+ COMMAND_PREFIX="bundle exec"
9
+ fi
10
+
11
+ if ! command -v rubocop-daemon > /dev/null; then
12
+ $COMMAND_PREFIX rubocop $@
13
+ exit $?
14
+ fi
15
+
4
16
  if [[ "$OSTYPE" == "linux-gnu" ]]; then
5
- NETCAT_CMD="nc -N"
17
+ if [ -f "/etc/fedora-release" ]; then
18
+ NETCAT_CMD="nc"
19
+ else
20
+ NETCAT_CMD="nc -N"
21
+ fi
6
22
  elif [[ "$OSTYPE" == "darwin"* ]]; then
7
23
  NETCAT_CMD="nc"
8
24
  elif [[ "$OSTYPE" == "freebsd"* ]]; then
@@ -46,16 +62,42 @@ TOKEN_PATH="$PROJECT_CACHE_DIR/token"
46
62
  PORT_PATH="$PROJECT_CACHE_DIR/port"
47
63
  STDIN_PATH="$PROJECT_CACHE_DIR/stdin"
48
64
  STATUS_PATH="$PROJECT_CACHE_DIR/status"
65
+ LOCK_PATH="$CACHE_DIR/running.lock"
66
+ RUBOCOP_DAEMON="$COMMAND_PREFIX rubocop-daemon"
67
+
68
+ # If a lock file exist, wait up to 5 seconds.
69
+ i=0
70
+ while [ -d "$LOCK_PATH" ]; do
71
+ echo "rubocop-daemon-wrapper: rubocop-daemon is processing a request; pausing before trying again..." >&2
72
+ sleep 1
73
+ i=$((i + 1))
74
+ if [ $i -ge 5 ]; then
75
+ echo "rubocop-daemon-wrapper: Waited more than 5 seconds; ignoring the lock and proceeding." >&2
76
+ break
77
+ fi
78
+ done
79
+
80
+ unlock() {
81
+ rm -r "$LOCK_PATH" 2> /dev/null
82
+ }
83
+
84
+ trap unlock EXIT
85
+
86
+ # Acquire a file lock before proceeding.
87
+ # Macs don't support the `lockfile` command, so just use mkdir.
88
+ mkdir -p "$LOCK_PATH"
49
89
 
50
90
  # If -s or --stdin args are present, read stdin with `cat`
51
91
  for ARG in $@; do
52
92
  if [ -z "$STDIN_CONTENT" ] && [ "$ARG" == "--stdin" ] || [ "$ARG" == "-s" ]; then
53
- STDIN_CONTENT="\n$(cat)"
93
+ # Preserve final new lines when ingesting from STDIN
94
+ STDIN_CONTENT="$(cat; printf x)"
95
+ STDIN_CONTENT=${STDIN_CONTENT%x}
54
96
  fi
55
97
  done
56
98
 
57
99
  if [ ! -f "$TOKEN_PATH" ]; then
58
- rubocop-daemon start
100
+ $RUBOCOP_DAEMON start
59
101
  fi
60
102
 
61
103
  run_rubocop_command() {
@@ -63,7 +105,7 @@ run_rubocop_command() {
63
105
  PORT="$(cat "$PORT_PATH")"
64
106
  COMMAND="$TOKEN $PROJECT_ROOT exec $@"
65
107
  rm -f "$STATUS_PATH" # Clear the previous status
66
- if echo -e "$COMMAND${STDIN_CONTENT}" | $NETCAT_CMD localhost "$PORT"; then
108
+ if printf '%s\n%s' "$COMMAND" "$STDIN_CONTENT" | $NETCAT_CMD localhost "$PORT"; then
67
109
  if [ -f "$STATUS_PATH" ]; then
68
110
  exit "$(cat $STATUS_PATH)"
69
111
  else
@@ -80,7 +122,7 @@ if ! run_rubocop_command $@; then
80
122
  rm -rf "$CACHE_DIR"
81
123
  pkill -f "rubocop-daemon (re)?start"
82
124
  echo "Starting new rubocop-daemon server..." >&2
83
- rubocop-daemon start
125
+ $RUBOCOP_DAEMON start
84
126
  if ! run_rubocop_command $@; then
85
127
  echo "Sorry, something went wrong with rubocop-daemon!" >&2
86
128
  echo "Please try updating the gem or re-installing the rubocop-daemon-wrapper script."
@@ -28,7 +28,7 @@ module RuboCop
28
28
  raise "rubocop-daemon: Could not find status file at: #{Cache.status_path}" unless Cache.status_path.file?
29
29
 
30
30
  status = Cache.status_path.read
31
- raise "rubocop-daemon: '#{status}' is not a valid status!" unless status.match?(/^\d+$/)
31
+ raise "rubocop-daemon: '#{status}' is not a valid status!" if (status =~ /^\d+$/).nil?
32
32
 
33
33
  exit status.to_i
34
34
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module Daemon
5
- VERSION = '0.3.1'.freeze
5
+ VERSION = '0.3.2'.freeze
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-daemon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hayato Kawai
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-12-20 00:00:00.000000000 Z
11
+ date: 2019-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -139,8 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
139
  - !ruby/object:Gem::Version
140
140
  version: '0'
141
141
  requirements: []
142
- rubyforge_project:
143
- rubygems_version: 2.7.6
142
+ rubygems_version: 3.0.1
144
143
  signing_key:
145
144
  specification_version: 4
146
145
  summary: Makes RuboCop faster