permpress 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/.rspec +2 -0
  4. data/.rubocop.yml +18 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +56 -0
  8. data/Rakefile +6 -0
  9. data/bin/permpress +5 -0
  10. data/lib/permpress.rb +2 -0
  11. data/lib/permpress/checkstyle.rb +26 -0
  12. data/lib/permpress/checkstyle/checkstyle_logger-all.jar +0 -0
  13. data/lib/permpress/checkstyle/sun_checks.xml +177 -0
  14. data/lib/permpress/cli.rb +43 -0
  15. data/lib/permpress/coffeelint.rb +27 -0
  16. data/lib/permpress/coffeelint/lintci.coffee +12 -0
  17. data/lib/permpress/command.rb +42 -0
  18. data/lib/permpress/csslint.rb +63 -0
  19. data/lib/permpress/golint.rb +12 -0
  20. data/lib/permpress/govet.rb +7 -0
  21. data/lib/permpress/jshint.rb +23 -0
  22. data/lib/permpress/jshint/formatter.js +23 -0
  23. data/lib/permpress/jslint.rb +7 -0
  24. data/lib/permpress/jsonlint.rb +19 -0
  25. data/lib/permpress/rubocop.rb +28 -0
  26. data/lib/permpress/rubocop/formatter.rb +22 -0
  27. data/lib/permpress/scsslint.rb +24 -0
  28. data/lib/permpress/scsslint/scsslint +37 -0
  29. data/lib/permpress/version.rb +4 -0
  30. data/permpress.gemspec +27 -0
  31. data/spec/fixtures/Good.java +6 -0
  32. data/spec/fixtures/bad.coffee +1 -0
  33. data/spec/fixtures/bad.css +4 -0
  34. data/spec/fixtures/bad.go +7 -0
  35. data/spec/fixtures/bad.java +3 -0
  36. data/spec/fixtures/bad.js +3 -0
  37. data/spec/fixtures/bad.json +4 -0
  38. data/spec/fixtures/bad.rb +4 -0
  39. data/spec/fixtures/bad.scss +3 -0
  40. data/spec/fixtures/good.coffee +1 -0
  41. data/spec/fixtures/good.css +3 -0
  42. data/spec/fixtures/good.go +7 -0
  43. data/spec/fixtures/good.js +5 -0
  44. data/spec/fixtures/good.json +4 -0
  45. data/spec/fixtures/good.rb +5 -0
  46. data/spec/fixtures/good.scss +3 -0
  47. data/spec/fixtures/lint.txt +1 -0
  48. data/spec/permpress/checkstyle_spec.rb +66 -0
  49. data/spec/permpress/coffeelint_spec.rb +64 -0
  50. data/spec/permpress/command_spec.rb +37 -0
  51. data/spec/permpress/csslint_spec.rb +65 -0
  52. data/spec/permpress/golint_spec.rb +43 -0
  53. data/spec/permpress/jshint_spec.rb +65 -0
  54. data/spec/permpress/jsonlint_spec.rb +45 -0
  55. data/spec/permpress/rubocop_spec.rb +67 -0
  56. data/spec/permpress/scsslint_spec.rb +62 -0
  57. data/spec/permpress_spec.rb +7 -0
  58. data/spec/spec_helper.rb +4 -0
  59. data/spec/support/exit_matcher.rb +15 -0
  60. data/spec/support/observed_output_context.rb +10 -0
  61. metadata +204 -0
@@ -0,0 +1,4 @@
1
+ {
2
+ "good": 1,
3
+ "not": "bad"
4
+ }
@@ -0,0 +1,5 @@
1
+ # Bob is useless
2
+ class Bob
3
+ def x_man
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ p {
2
+ border: 0;
3
+ }
@@ -0,0 +1 @@
1
+ lint
@@ -0,0 +1,66 @@
1
+ require 'spec_helper'
2
+
3
+ describe Permpress::Checkstyle do
4
+ describe '#lint', :unit do
5
+ let(:permpress_path){File.expand_path('../../..', __FILE__)}
6
+
7
+ context 'when config flag is present' do
8
+ it 'executes command with expected arguments' do
9
+ expect(Permpress::Command).to receive(:new).with(
10
+ 'java',
11
+ %w(Good.java bad.java),
12
+ %W(
13
+ -jar #{permpress_path}/lib/permpress/checkstyle/checkstyle_logger-all.jar
14
+ -c checks.xml
15
+ )
16
+ ).and_return(instance_double(Permpress::Command, run: nil))
17
+
18
+ Permpress::Checkstyle.start(['lint', '--config', 'checks.xml', 'Good.java', 'bad.java'])
19
+ end
20
+ end
21
+
22
+ context 'when config flag is not present' do
23
+ it 'executes command with expected arguments' do
24
+ expect(Permpress::Command).to receive(:new).with(
25
+ 'java',
26
+ %w(Good.java bad.java),
27
+ %W(
28
+ -jar #{permpress_path}/lib/permpress/checkstyle/checkstyle_logger-all.jar
29
+ -c #{permpress_path}/lib/permpress/checkstyle/sun_checks.xml
30
+ )
31
+ ).and_return(instance_double(Permpress::Command, run: nil))
32
+
33
+ Permpress::Checkstyle.start(['lint', 'Good.java', 'bad.java'])
34
+ end
35
+ end
36
+ end
37
+
38
+ describe '#lint', :integration do
39
+ include_context 'observed output'
40
+
41
+ context 'when the file is not lint free' do
42
+ let(:file){File.expand_path('../../fixtures/bad.java', __FILE__)}
43
+
44
+ it 'generates the expected output' do
45
+ expect{Permpress::CLI.start(['checkstyle', 'lint', file])}.to_not exit_successfully
46
+
47
+ expect($stdout.string).to eq(
48
+ "#{file}:1:0::com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocTypeCheck:error:"\
49
+ "Missing a Javadoc comment.\n"\
50
+ "#{file}:1:14::com.puppycrawl.tools.checkstyle.checks.naming.TypeNameCheck:error:"\
51
+ "Name 'bad' must match pattern '^[A-Z][a-zA-Z0-9]*$'.\n"
52
+ )
53
+ end
54
+ end
55
+
56
+ context 'when the file is lint free' do
57
+ let(:file){File.expand_path('../../fixtures/Good.java', __FILE__)}
58
+
59
+ it 'generates the expected output' do
60
+ expect{Permpress::CLI.start(['checkstyle', 'lint', file])}.to exit_successfully
61
+
62
+ expect($stdout.string).to eq('')
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+
3
+ describe Permpress::CoffeeLint do
4
+ describe '#lint', :unit do
5
+ let(:permpress_path){File.expand_path('../../..', __FILE__)}
6
+
7
+ context 'when config flag is present' do
8
+ it 'executes command with expected arguments' do
9
+ expect(Permpress::Command).to receive(:new).with(
10
+ 'coffeelint',
11
+ %w(good.coffee bad.coffee),
12
+ %W(
13
+ --reporter=#{permpress_path}/lib/permpress/coffeelint/lintci.coffee
14
+ --nocolor
15
+ --file=coffeelint.json
16
+ )
17
+ ).and_return(instance_double(Permpress::Command, run: nil))
18
+
19
+ Permpress::CoffeeLint.start(['lint', '--config', 'coffeelint.json', 'good.coffee', 'bad.coffee'])
20
+ end
21
+ end
22
+
23
+ context 'when config flag is not present' do
24
+ it 'executes command with expected arguments' do
25
+ expect(Permpress::Command).to receive(:new).with(
26
+ 'coffeelint',
27
+ %w(good.coffee bad.coffee),
28
+ %W(
29
+ --reporter=#{permpress_path}/lib/permpress/coffeelint/lintci.coffee
30
+ --nocolor
31
+ )
32
+ ).and_return(instance_double(Permpress::Command, run: nil))
33
+
34
+ Permpress::CoffeeLint.start(['lint', 'good.coffee', 'bad.coffee'])
35
+ end
36
+ end
37
+ end
38
+
39
+ describe '#lint', :integration do
40
+ include_context 'observed output'
41
+
42
+ context 'when the file is not lint free' do
43
+ let(:file){File.expand_path('../../fixtures/bad.coffee', __FILE__)}
44
+
45
+ it 'generates the expected output' do
46
+ expect{Permpress::CLI.start(['coffeelint', 'lint', file])}.to_not exit_successfully
47
+
48
+ expect($stdout.string).to eq(
49
+ "#{file}:1:::camel_case_classes:error:Class names should be camel cased\n"
50
+ )
51
+ end
52
+ end
53
+
54
+ context 'when the file is lint free' do
55
+ let(:file){File.expand_path('../../fixtures/good.coffee', __FILE__)}
56
+
57
+ it 'generates the expected output' do
58
+ expect{Permpress::CLI.start(['coffeelint', 'lint', file])}.to exit_successfully
59
+
60
+ expect($stdout.string).to eq('')
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+ require 'stringio'
3
+
4
+ describe Permpress::Command do
5
+ let(:file){'fake file.txt'}
6
+ let(:command){Permpress::Command.new('cat', [file], %w(-b))}
7
+
8
+ describe '#run' do
9
+ let(:output){StringIO.new}
10
+
11
+ context 'when command is successfully run' do
12
+ let(:file){File.expand_path('../../fixtures/lint.txt', __FILE__)}
13
+
14
+ it 'generates the expected output' do
15
+ expect{command.run(output)}.to exit_successfully
16
+
17
+ expect(output.string).to eq(" 1\tlint\n")
18
+ end
19
+ end
20
+
21
+ context 'when command is unsuccessfully run' do
22
+ let(:command){Permpress::Command.new('this-command-does-not-exist', [file], %w(-b))}
23
+
24
+ it 'generates the expected output' do
25
+ expect{command.run(output)}.to_not exit_successfully
26
+
27
+ expect(output.string).to eq("sh: this-command-does-not-exist: command not found\n")
28
+ end
29
+ end
30
+ end
31
+
32
+ describe '#command/#to_s' do
33
+ it 'generates an executable command' do
34
+ expect(command.command).to eq('cat -b fake\ file.txt 2>&1')
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,65 @@
1
+ require 'spec_helper'
2
+
3
+ describe Permpress::CSSLint do
4
+ describe '#lint', :unit do
5
+ let(:permpress_path){File.expand_path('../../..', __FILE__)}
6
+
7
+ context 'when config flag is present' do
8
+ it 'executes command with expected arguments' do
9
+ expect(Permpress::Command).to receive(:new).with(
10
+ 'csslint',
11
+ %w(good.css bad.css),
12
+ %W(
13
+ --errors=#{Permpress::CSSLint::RULES}
14
+ --format=compact
15
+ --config=.csslintrc
16
+ )
17
+ ).and_return(instance_double(Permpress::Command, run: nil))
18
+
19
+ Permpress::CSSLint.start(['lint', '--config', '.csslintrc', 'good.css', 'bad.css'])
20
+ end
21
+ end
22
+
23
+ context 'when config flag is not present' do
24
+ it 'executes command with expected arguments' do
25
+ expect(Permpress::Command).to receive(:new).with(
26
+ 'csslint',
27
+ %w(good.css bad.css),
28
+ %W(
29
+ --errors=#{Permpress::CSSLint::RULES}
30
+ --format=compact
31
+ )
32
+ ).and_return(instance_double(Permpress::Command, run: nil))
33
+
34
+ Permpress::CSSLint.start(['lint', 'good.css', 'bad.css'])
35
+ end
36
+ end
37
+ end
38
+
39
+ describe '#lint', :integration do
40
+ include_context 'observed output'
41
+
42
+ context 'when the file is not lint free' do
43
+ let(:file){File.expand_path('../../fixtures/bad.css', __FILE__)}
44
+
45
+ it 'generates the expected output' do
46
+ expect{Permpress::CLI.start(['csslint', 'lint', file])}.to_not exit_successfully
47
+
48
+ expect($stdout.string).to eq(
49
+ "#{file}: line 2, col 5, Error - Using width with border can sometimes"\
50
+ " make elements larger than you expect.\n\n"
51
+ )
52
+ end
53
+ end
54
+
55
+ context 'when the file is lint free' do
56
+ let(:file){File.expand_path('../../fixtures/good.css', __FILE__)}
57
+
58
+ it 'generates the expected output' do
59
+ expect{Permpress::CLI.start(['csslint', 'lint', file])}.to exit_successfully
60
+
61
+ expect($stdout.string).to eq("#{file}: Lint Free!\n")
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ describe Permpress::GoLint do
4
+ describe '#lint', :unit do
5
+ let(:permpress_path){File.expand_path('../../..', __FILE__)}
6
+
7
+ it 'executes command with expected arguments' do
8
+ expect(Permpress::Command).to receive(:new).with(
9
+ 'fgt golint',
10
+ %w(good.go bad.go),
11
+ []
12
+ ).and_return(instance_double(Permpress::Command, run: nil))
13
+
14
+ Permpress::GoLint.start(['lint', 'good.go', 'bad.go'])
15
+ end
16
+ end
17
+
18
+ describe '#lint', :integration do
19
+ include_context 'observed output'
20
+
21
+ context 'when the file is not lint free' do
22
+ let(:file){File.expand_path('../../fixtures/bad.go', __FILE__)}
23
+
24
+ it 'generates the expected output' do
25
+ expect{Permpress::CLI.start(['golint', 'lint', file])}.to_not exit_successfully
26
+
27
+ expect($stdout.string).to eq(
28
+ "#{file}:5:1: exported function Main should have comment or be unexported\n"
29
+ )
30
+ end
31
+ end
32
+
33
+ context 'when the file is lint free' do
34
+ let(:file){File.expand_path('../../fixtures/good.go', __FILE__)}
35
+
36
+ it 'generates the expected output' do
37
+ expect{Permpress::CLI.start(['golint', 'lint', file])}.to exit_successfully
38
+
39
+ expect($stdout.string).to eq('')
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,65 @@
1
+ require 'spec_helper'
2
+
3
+ describe Permpress::JSHint do
4
+ describe '#lint', :unit do
5
+ let(:permpress_path){File.expand_path('../../..', __FILE__)}
6
+
7
+ context 'when config flag is present' do
8
+ it 'executes command with expected arguments' do
9
+ expect(Permpress::Command).to receive(:new).with(
10
+ 'jshint',
11
+ %w(good.js bad.js),
12
+ %W(
13
+ --reporter #{permpress_path}/lib/permpress/jshint/formatter.js
14
+ --config .jshintrc
15
+ )
16
+ ).and_return(instance_double(Permpress::Command, run: nil))
17
+
18
+ Permpress::JSHint.start(['lint', '--config', '.jshintrc', 'good.js', 'bad.js'])
19
+ end
20
+ end
21
+
22
+ context 'when config flag is not present' do
23
+ it 'executes command with expected arguments' do
24
+ expect(Permpress::Command).to receive(:new).with(
25
+ 'jshint',
26
+ %w(good.js bad.js),
27
+ %W(
28
+ --reporter #{permpress_path}/lib/permpress/jshint/formatter.js
29
+ )
30
+ ).and_return(instance_double(Permpress::Command, run: nil))
31
+
32
+ Permpress::JSHint.start(['lint', 'good.js', 'bad.js'])
33
+ end
34
+ end
35
+ end
36
+
37
+ describe '#lint', :integration do
38
+ include_context 'observed output'
39
+
40
+ context 'when the file is not lint free' do
41
+ let(:file){File.expand_path('../../fixtures/bad.js', __FILE__)}
42
+
43
+ it 'generates the expected output' do
44
+ expect{Permpress::CLI.start(['jshint', 'lint', file])}.to_not exit_successfully
45
+
46
+ expect($stdout.string).to eq(
47
+ "#{file}:2:13::E031:error:Bad assignment.\n"\
48
+ "#{file}:2:13::W030:warning:Expected an assignment or function call and instead saw an expression.\n"\
49
+ "#{file}:2:14::W033:warning:Missing semicolon.\n"\
50
+ "#{file}:2:15::W030:warning:Expected an assignment or function call and instead saw an expression.\n"
51
+ )
52
+ end
53
+ end
54
+
55
+ context 'when the file is lint free' do
56
+ let(:file){File.expand_path('../../fixtures/good.js', __FILE__)}
57
+
58
+ it 'generates the expected output' do
59
+ expect{Permpress::CLI.start(['jshint', 'lint', file])}.to exit_successfully
60
+
61
+ expect($stdout.string).to eq('')
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ describe Permpress::JSONLint do
4
+ describe '#lint', :unit do
5
+ let(:permpress_path){File.expand_path('../../..', __FILE__)}
6
+
7
+ it 'executes command with expected arguments' do
8
+ expect(Permpress::Command).to receive(:new).with(
9
+ 'durable-json-lint',
10
+ %w(good.json bad.json),
11
+ ['--format', '{{file}}:{{line}}:{{column}}:::error:{{{description}}}']
12
+ ).and_return(instance_double(Permpress::Command, run: nil))
13
+
14
+ Permpress::JSONLint.start(['lint', 'good.json', 'bad.json'])
15
+ end
16
+ end
17
+
18
+ describe '#lint', :integration do
19
+ include_context 'observed output'
20
+
21
+ context 'when the file is not lint free' do
22
+ let(:file){File.expand_path('../../fixtures/bad.json', __FILE__)}
23
+
24
+ it 'generates the expected output' do
25
+ expect{Permpress::CLI.start(['jsonlint', 'lint', file])}.to_not exit_successfully
26
+
27
+ expect($stdout.string).to eq(
28
+ "#{file}:2:2:::error:Json strings must use double quotes\n"\
29
+ "#{file}:3:2:::error:Keys must be double quoted in Json. Did you mean \"not\"?\n"\
30
+ "#{file}:3:7:::error:Invalid Json number\n"
31
+ )
32
+ end
33
+ end
34
+
35
+ context 'when the file is lint free' do
36
+ let(:file){File.expand_path('../../fixtures/good.json', __FILE__)}
37
+
38
+ it 'generates the expected output' do
39
+ expect{Permpress::CLI.start(['jsonlint', 'lint', file])}.to exit_successfully
40
+
41
+ expect($stdout.string).to eq('')
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,67 @@
1
+ require 'spec_helper'
2
+
3
+ describe Permpress::RuboCop do
4
+ describe '#lint', :unit do
5
+ let(:permpress_path){File.expand_path('../../..', __FILE__)}
6
+
7
+ context 'when config flag is present' do
8
+ it 'executes command with expected arguments' do
9
+ expect(Permpress::Command).to receive(:new).with(
10
+ 'rubocop',
11
+ %w(good.rb bad.rb),
12
+ %W(
13
+ --require #{permpress_path}/lib/permpress/rubocop/formatter.rb
14
+ --format Permpress::Rubocop::Formatter
15
+ --no-color
16
+ --config .rubocop.yml
17
+ )
18
+ ).and_return(instance_double(Permpress::Command, run: nil))
19
+
20
+ Permpress::RuboCop.start(['lint', '--config', '.rubocop.yml', 'good.rb', 'bad.rb'])
21
+ end
22
+ end
23
+
24
+ context 'when config flag is not present' do
25
+ it 'executes command with expected arguments' do
26
+ expect(Permpress::Command).to receive(:new).with(
27
+ 'rubocop',
28
+ %w(good.rb bad.rb),
29
+ %W(
30
+ --require #{permpress_path}/lib/permpress/rubocop/formatter.rb
31
+ --format Permpress::Rubocop::Formatter
32
+ --no-color
33
+ )
34
+ ).and_return(instance_double(Permpress::Command, run: nil))
35
+
36
+ Permpress::RuboCop.start(['lint', 'good.rb', 'bad.rb'])
37
+ end
38
+ end
39
+ end
40
+
41
+ describe '#lint', :integration do
42
+ include_context 'observed output'
43
+
44
+ context 'when the file is not lint free' do
45
+ let(:file){File.expand_path('../../fixtures/bad.rb', __FILE__)}
46
+
47
+ it 'generates the expected output' do
48
+ expect{Permpress::CLI.start(['rubocop', 'lint', file])}.to_not exit_successfully
49
+
50
+ expect($stdout.string).to eq(
51
+ "#{file}:1:1:5:Style/Documentation:convention:Missing top-level class documentation comment.\n"\
52
+ "#{file}:2:7:4:Style/MethodName:convention:Use snake_case for methods.\n"
53
+ )
54
+ end
55
+ end
56
+
57
+ context 'when the file is lint free' do
58
+ let(:file){File.expand_path('../../fixtures/good.rb', __FILE__)}
59
+
60
+ it 'generates the expected output' do
61
+ expect{Permpress::CLI.start(['rubocop', 'lint', file])}.to exit_successfully
62
+
63
+ expect($stdout.string).to eq('')
64
+ end
65
+ end
66
+ end
67
+ end