permpress 0.0.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 (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,42 @@
1
+ require 'open3'
2
+ require 'shellwords'
3
+
4
+ module Permpress
5
+ # Generic command interface to execute a command with it's arguments, pipe the output, and exit correctly.
6
+ class Command
7
+ attr_reader :executable, :files, :options
8
+
9
+ def initialize(executable, files, options = [])
10
+ @executable = executable
11
+ @files = files
12
+ @options = options
13
+ end
14
+
15
+ def run(io = $stdout)
16
+ Bundler.with_clean_env do
17
+ Open3.popen3(command) do |_, stdout, _, thread|
18
+ stdout.each do |line|
19
+ io.puts line
20
+ end
21
+
22
+ exit thread.value.exitstatus
23
+ end
24
+ end
25
+ end
26
+
27
+ def command
28
+ "#{executable} #{flags} #{arguments} 2>&1"
29
+ end
30
+ alias_method :to_s, :command
31
+
32
+ private
33
+
34
+ def flags
35
+ Shellwords.join(options)
36
+ end
37
+
38
+ def arguments
39
+ Shellwords.join(files)
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,63 @@
1
+ require 'thor'
2
+ require_relative 'command'
3
+
4
+ module Permpress
5
+ # CSS Lint subcommand. Calls CSS Lint with the correct arguments.
6
+ class CSSLint < Thor
7
+ desc 'lint [FILES]', 'Runs linter'
8
+ method_option :config, banner: 'CONFIG_FILE'
9
+
10
+ def lint(*files)
11
+ Command.new('csslint', files, flags).run
12
+ end
13
+
14
+ private
15
+
16
+ def flags
17
+ [
18
+ "--errors=#{RULES}",
19
+ '--format=compact'
20
+ ].tap do |flags|
21
+ flags.concat(["--config=#{options[:config]}"]) if options[:config]
22
+ end
23
+ end
24
+
25
+ RULES = %w(
26
+ important
27
+ adjoining-classes
28
+ known-properties
29
+ box-sizing
30
+ box-model
31
+ overqualified-elements
32
+ display-property-grouping
33
+ bulletproof-font-face
34
+ compatible-vendor-prefixes
35
+ regex-selectors
36
+ errors
37
+ duplicate-background-images
38
+ duplicate-properties
39
+ empty-rules
40
+ selector-max-approaching
41
+ gradients
42
+ fallback-colors
43
+ font-sizes
44
+ font-faces
45
+ floats
46
+ star-property-hack
47
+ outline-none
48
+ import
49
+ ids
50
+ underscore-property-hack
51
+ rules-count
52
+ qualified-headings
53
+ selector-max
54
+ shorthand
55
+ text-indent
56
+ unique-headings
57
+ universal-selector
58
+ unqualified-attributes
59
+ vendor-prefix
60
+ zero-units
61
+ ).join(',')
62
+ end
63
+ end
@@ -0,0 +1,12 @@
1
+ require 'thor'
2
+ require_relative 'command'
3
+
4
+ module Permpress
5
+ class GoLint < Thor
6
+ desc 'lint [FILES]', 'Runs linter'
7
+
8
+ def lint(*files)
9
+ Command.new('fgt golint', files, []).run
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,7 @@
1
+ require 'thor'
2
+ require_relative 'command'
3
+
4
+ module Permpress
5
+ class GoVet < Thor
6
+ end
7
+ end
@@ -0,0 +1,23 @@
1
+ require 'thor'
2
+ require_relative 'command'
3
+
4
+ module Permpress
5
+ class JSHint < Thor
6
+ FORMATTER_PATH = File.expand_path('../jshint/formatter.js', __FILE__)
7
+
8
+ desc 'lint [FILES]', 'Runs linter'
9
+ method_option :config, banner: 'CONFIG_FILE'
10
+
11
+ def lint(*files)
12
+ Command.new('jshint', files, flags).run
13
+ end
14
+
15
+ private
16
+
17
+ def flags
18
+ ['--reporter', FORMATTER_PATH].tap do |flags|
19
+ flags.concat(['--config', options[:config]]) if options[:config]
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+
2
+ module.exports = {
3
+ reporter: function (results, data, opts) {
4
+ 'use strict';
5
+
6
+ results.forEach(function (result) {
7
+ var file = result.file,
8
+ error = result.error,
9
+ line = error.line,
10
+ column = error.character,
11
+ rule = error.code,
12
+ severity = rule[0] === 'E' ? 'error' : 'warning',
13
+ message = error.reason;
14
+
15
+ console.log(file + ':' +
16
+ line + ':' +
17
+ column + '::' +
18
+ rule + ':' +
19
+ severity + ':' +
20
+ message);
21
+ });
22
+ }
23
+ };
@@ -0,0 +1,7 @@
1
+ require 'thor'
2
+ require_relative 'command'
3
+
4
+ module Permpress
5
+ class JSLint < Thor
6
+ end
7
+ end
@@ -0,0 +1,19 @@
1
+ require 'thor'
2
+ require_relative 'command'
3
+
4
+ module Permpress
5
+ # JSON Lint subcommand. Calls durable-json-lint with correct arguments.
6
+ class JSONLint < Thor
7
+ desc 'lint [FILES]', 'Runs linter'
8
+
9
+ def lint(*files)
10
+ Command.new('durable-json-lint', files, flags).run
11
+ end
12
+
13
+ private
14
+
15
+ def flags
16
+ ['--format', '{{file}}:{{line}}:{{column}}:::error:{{{description}}}']
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,28 @@
1
+ require 'thor'
2
+ require_relative 'command'
3
+
4
+ module Permpress
5
+ # Rubocop subcommand. Calls Rubocop with correct arguments.
6
+ class RuboCop < Thor
7
+ FORMATTER_PATH = File.expand_path('../rubocop/formatter.rb', __FILE__)
8
+
9
+ desc 'lint [FILES]', 'Runs linter'
10
+ method_option :config, banner: 'CONFIG_FILE'
11
+
12
+ def lint(*files)
13
+ Command.new('rubocop', files, flags).run
14
+ end
15
+
16
+ private
17
+
18
+ def flags
19
+ [
20
+ '--require', FORMATTER_PATH,
21
+ '--format', 'Permpress::Rubocop::Formatter',
22
+ '--no-color'
23
+ ].tap do |flags|
24
+ flags.concat(['--config', options[:config]]) if options[:config]
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,22 @@
1
+ module Permpress
2
+ class Rubocop
3
+ # Formats Rubocop output for LintCI
4
+ class Formatter < ::RuboCop::Formatter::BaseFormatter
5
+ LINE_FORMAT = "%s:%d:%d:%d:%s:%s:%s\n"
6
+
7
+ def file_finished(file, offenses)
8
+ offenses.each do |offense|
9
+ line = offense.line
10
+ column = offense.real_column
11
+ length = offense.location.length
12
+
13
+ rule = offense.cop_name
14
+ severity = offense.severity.name
15
+ message = offense.message
16
+
17
+ output.printf(LINE_FORMAT, file, line, column, length, rule, severity, message)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,24 @@
1
+ require 'thor'
2
+ require_relative 'command'
3
+
4
+ module Permpress
5
+ # SCSS Lint subcommand. Calls SCSS Lint with the correct arguments.
6
+ class SCSSLint < Thor
7
+ desc 'lint [FILES]', 'Runs linter'
8
+ method_option :config, banner: 'CONFIG_FILE'
9
+
10
+ PROGRAM = File.expand_path('../scsslint/scsslint', __FILE__)
11
+
12
+ def lint(*files)
13
+ Command.new(PROGRAM, files, flags).run
14
+ end
15
+
16
+ private
17
+
18
+ def flags
19
+ ['--format=LintCI'].tap do |flags|
20
+ flags.concat(["--config=#{options[:config]}"]) if options[:config]
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'scss_lint'
4
+ require 'scss_lint/cli'
5
+
6
+ module SCSSLint
7
+ class Reporter
8
+ # Formats SCSS Lint output for LintCI
9
+ class LintCIReporter < Reporter
10
+ LINE_FORMAT = "%s:%d:%d:%d:%s:%s:%s\n"
11
+
12
+ def report_lints
13
+ return unless lints.any?
14
+
15
+ lints.map{|lint| LINE_FORMAT % variables(lint)}.join('')
16
+ end
17
+
18
+ def variables(lint)
19
+ file = lint.filename
20
+ line = lint.location.line
21
+ column = lint.location.column
22
+ length = lint.location.length
23
+
24
+ rule = lint.linter ? lint.linter.name : ''
25
+ severity = lint.severity.to_s
26
+ message = lint.description
27
+
28
+ [file, line, column, length, rule, severity, message]
29
+ end
30
+ end
31
+ end
32
+ end
33
+
34
+ SCSSLint::CLI.new(ARGV).tap do |cli|
35
+ cli.parse_arguments
36
+ cli.run
37
+ end
@@ -0,0 +1,4 @@
1
+ # Namespace for linters
2
+ module Permpress
3
+ VERSION = '0.0.1'
4
+ end
data/permpress.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'permpress/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'permpress'
8
+ spec.version = Permpress::VERSION
9
+ spec.authors = ['Allen Madsen']
10
+ spec.email = ['blatyo@gmail.com']
11
+ spec.summary = 'Standardizes execution of various linters.'
12
+ spec.description = 'Standardizes execution of various linters.'
13
+ spec.homepage = 'https://github.com/lintci/permpress'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\u0000")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_runtime_dependency 'thor'
22
+ spec.add_runtime_dependency 'bundler'
23
+
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'rspec'
26
+ spec.add_development_dependency 'pry-byebug'
27
+ end
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Does absolutely nothing but pass lint checks.
3
+ */
4
+ public class Good {
5
+
6
+ }
@@ -0,0 +1 @@
1
+ class xMen
@@ -0,0 +1,4 @@
1
+ .mybox {
2
+ border: 1px solid black;
3
+ width: 100px;
4
+ }
@@ -0,0 +1,7 @@
1
+ package main
2
+
3
+ import "fmt"
4
+
5
+ func Main() {
6
+ fmt.Println("hello world")
7
+ }
@@ -0,0 +1,3 @@
1
+ public class bad {
2
+
3
+ }
@@ -0,0 +1,3 @@
1
+ function example() {
2
+ example() = 1;
3
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ 'bad': 1,
3
+ not: /good/
4
+ }
@@ -0,0 +1,4 @@
1
+ class Bob
2
+ def xMan
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ p {
2
+ border: none;
3
+ }
@@ -0,0 +1 @@
1
+ class XMen
@@ -0,0 +1,3 @@
1
+ .mybox {
2
+ width: 100px;
3
+ }
@@ -0,0 +1,7 @@
1
+ package main
2
+
3
+ import "fmt"
4
+
5
+ func main() {
6
+ fmt.Println("hello world")
7
+ }
@@ -0,0 +1,5 @@
1
+ function main() {
2
+ if(true === 1) return '===';
3
+ }
4
+
5
+ main();