roger_jshint 1.0.0 → 1.1.0

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
  SHA1:
3
- metadata.gz: 837f852c6ef0278395df76946e093ee4c52cea1f
4
- data.tar.gz: 9c97f2e5133a029712a8c26fca0c21a96447d632
3
+ metadata.gz: d14bd88e5858be37ebc958542a004606ead19cfb
4
+ data.tar.gz: c2cf5c3648a17610a1d3d91c53c3157a29bce5a1
5
5
  SHA512:
6
- metadata.gz: eb42fd286eb3eeef32bbe615d53483847b2a30afbf7766b3d97833a60fa3753731bda7cf2b122b10fe2e824d3593b880853fb267f2ef915f47bb49bf9eb7cf2b
7
- data.tar.gz: 714fabeb549664e72c04c40516acf1c233275e7302236b7a8323fb4bd3949ba9c83d447d1059a7ddc3d6dde257576e55b1649453171a2e991bcc1170d01b2064
6
+ metadata.gz: 43e9915df854a9d385b3e53c8e4c5c6b56b6a6fbc884339b1c7089fec8a06961398c6b172d26cbc61051c0237122ef4e40e948ad1e70662501491ba93d11e067
7
+ data.tar.gz: a3df08386e01204e31d6e2ac9b670825d78a811c71d9bbf8ad6bb6c37325d656dc072dbb9548b0c8a285b7e3fdabba924b0e600a88afe638011b6505cee946fd
data/.rubocop.yml CHANGED
@@ -1,17 +1,15 @@
1
1
  LineLength:
2
+ Description: 'Limit lines to 100 characters.'
2
3
  Max: 100
4
+ Enabled: true
3
5
 
4
- Metrics/AbcSize:
5
- Enabled:
6
- False
6
+ StringLiterals:
7
+ EnforcedStyle: double_quotes
8
+ Enabled: true
7
9
 
8
- Style/HashSyntax:
9
- Enabled:
10
- False
11
-
12
- Style/StringLiterals:
13
- Enabled:
14
- False
10
+ Style/DotPosition:
11
+ EnforcedStyle: trailing
12
+ Enabled: true
15
13
 
16
14
  Metrics/MethodLength:
17
15
  CountComments: false # count full line comments?
data/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ # Changelog
2
+
3
+ ## Version 1.1.0
4
+ * Add a `.jshintrc` generator
5
+ * Correctly return success value so reger test will output the correct error code
6
+
7
+ ## Version 1.0.0
8
+ * What was before...
data/Gemfile CHANGED
@@ -1,3 +1,3 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
3
  gemspec
data/Rakefile CHANGED
@@ -1,15 +1,15 @@
1
- require 'rake/testtask'
2
- require 'rubocop/rake_task'
1
+ require "rake/testtask"
2
+ require "rubocop/rake_task"
3
3
 
4
- task :default => [:test, :rubocop]
4
+ task default: [:test, :rubocop]
5
5
 
6
- desc 'Run rubocop'
6
+ desc "Run rubocop"
7
7
  task :rubocop do
8
8
  RuboCop::RakeTask.new
9
9
  end
10
10
 
11
11
  Rake::TestTask.new do |t|
12
- t.libs << 'test'
13
- t.test_files = FileList['test/**/*_test.rb']
12
+ t.libs << "test"
13
+ t.test_files = FileList["test/**/*_test.rb"]
14
14
  t.verbose = true
15
15
  end
data/lib/roger_jshint.rb CHANGED
@@ -2,4 +2,4 @@
2
2
  module RogerJsHint
3
3
  end
4
4
 
5
- require File.dirname(__FILE__) + '/roger_jshint/lint'
5
+ require File.dirname(__FILE__) + "/roger_jshint/lint"
@@ -0,0 +1,45 @@
1
+ require "open-uri"
2
+
3
+ require "roger/cli/generate"
4
+ require "roger/cli/command"
5
+ require "roger/generators"
6
+
7
+ module RogerJsHint
8
+ # Lint configuration retriever
9
+ class Generator < Roger::Generators::Base
10
+ include Thor::Actions
11
+ CONFIG_PATH = ".jshintrc"
12
+ DEFAULT_CONFIG_URL = "https://raw.githubusercontent.com/"\
13
+ "DigitPaint/javascript/master/linters/jshintrc"
14
+
15
+ desc "JsHint generator creates an .jshintrc config file"
16
+ class_option(
17
+ :config,
18
+ type: :string,
19
+ aliases: ["-c"],
20
+ desc: "Optional config file to use takes a path or url, by
21
+ default it uses the company' default"
22
+ )
23
+
24
+ class_option(
25
+ :force,
26
+ type: :boolean,
27
+ aliases: ["-f"],
28
+ desc: "Always overwrite the config file"
29
+ )
30
+
31
+ # Write config file
32
+ def write_config_file
33
+ if options[:config]
34
+ config = open(options[:config]).read
35
+ else
36
+ config = open(DEFAULT_CONFIG_URL).read
37
+ end
38
+
39
+ # Create file check if we don't have a conflict or something
40
+ create_file "#{@project.path}/#{CONFIG_PATH}", config, force: options[:force]
41
+ end
42
+ end
43
+ end
44
+
45
+ Roger::Generators.register :jshint, RogerJsHint::Generator
@@ -1,6 +1,6 @@
1
- require 'shellwords'
2
- require 'json'
3
- require 'roger/test'
1
+ require "shellwords"
2
+ require "json"
3
+ require "roger/test"
4
4
 
5
5
  module RogerJsHint
6
6
  # JS linter plugin for Roger
@@ -11,20 +11,25 @@ module RogerJsHint
11
11
  # @option options [Array] :jshint Jshint command
12
12
  def initialize(options = {})
13
13
  @options = {
14
- :match => ['html/**/*.js'],
15
- :skip => [],
16
- :jshint => 'jshint'
14
+ match: ["html/**/*.js"],
15
+ skip: [],
16
+ jshint: "jshint"
17
17
  }
18
+ detect_jshint
19
+
18
20
  @options.update(options) if options
19
21
  end
20
22
 
21
- def detect_jshint
22
- command = [@options[:jshint], "-v", "2>/dev/null"]
23
- detect = system(Shellwords.join(command))
24
- fail 'Could not find jshint. Install jshint using npm.' unless detect
25
- end
23
+ def report(test, file_path)
24
+ command = [
25
+ @options[:jshint],
26
+ reporter
27
+ ]
28
+
29
+ # The actual linting
30
+ output = `#{Shellwords.join(command + [Shellwords.escape(file_path)])}`
31
+ lints = JSON.parse output
26
32
 
27
- def report(test, file_path, lints)
28
33
  success = true
29
34
  if lints.empty?
30
35
  test.log(self, "No erors in #{file_path}")
@@ -42,19 +47,25 @@ module RogerJsHint
42
47
  # @option options [Array[Regexp]] :skip Array of regular expressions to skip files
43
48
  def call(test, options)
44
49
  options = {}.update(@options).update(options)
45
- command = [
46
- @options[:jshint],
47
- "--reporter=" + File.expand_path('jsonreporter.js', File.dirname(__FILE__))
48
- ]
49
50
 
50
- detect_jshint
51
- test.log(self, 'JS-linting files')
51
+ test.log(self, "JS-linting files")
52
52
 
53
- test.get_files(options[:match], options[:skip]).each do |file_path|
54
- output = `#{Shellwords.join(command + [Shellwords.escape(file_path)])}`
55
- lint = JSON.parse output
56
- report(test, file_path, lint)
53
+ failures = test.get_files(options[:match], options[:skip]).select do |file_path|
54
+ !report(test, file_path)
57
55
  end
56
+ failures.empty?
57
+ end
58
+
59
+ private
60
+
61
+ def detect_jshint
62
+ command = [@options[:jshint], "-v", "2>/dev/null"]
63
+ detect = system(Shellwords.join(command))
64
+ fail "Could not find jshint. Install jshint using npm." unless detect
65
+ end
66
+
67
+ def reporter
68
+ "--reporter=" + File.expand_path("jsonreporter.js", File.dirname(__FILE__))
58
69
  end
59
70
  end
60
71
  end
data/roger_jshint.gemspec CHANGED
@@ -1,27 +1,29 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
3
  Gem::Specification.new do |s|
4
- s.authors = ['Hans Krutzer', 'Flurin Egger']
5
- s.email = ['info@digitpaint.nl', 'hans@digitpaint.nl', 'flurin@digitpaint.nl']
6
- s.name = 'roger_jshint'
7
- s.version = '1.0.0'
8
- s.homepage = 'https://github.com/digitpaint/roger_jshint'
4
+ s.authors = ["Hans Krutzer", "Flurin Egger"]
5
+ s.email = ["info@digitpaint.nl", "hans@digitpaint.nl", "flurin@digitpaint.nl"]
6
+ s.name = "roger_jshint"
7
+ s.version = "1.1.0"
8
+ s.homepage = "https://github.com/digitpaint/roger_jshint"
9
9
 
10
- s.summary = 'Lint JavaScript files within Roger'
10
+ s.summary = "Lint JavaScript files within Roger"
11
11
  s.description = <<-EOF
12
12
  Lint JavaScript files from within Roger, using jshint.
13
13
  Will use .jshintrc.
14
14
  EOF
15
- s.licenses = ['MIT']
15
+ s.licenses = ["MIT"]
16
16
 
17
- s.date = Time.now.strftime('%Y-%m-%d')
17
+ s.date = Time.now.strftime("%Y-%m-%d")
18
18
 
19
19
  s.files = `git ls-files`.split("\n")
20
- s.require_paths = ['lib']
20
+ s.require_paths = ["lib"]
21
21
 
22
- s.add_dependency 'roger', '~> 1.1', '>= 0.13.0'
22
+ s.add_dependency "roger", "~> 1.1", ">= 0.13.0"
23
23
 
24
- s.add_development_dependency 'rubocop', ['>= 0']
25
- s.add_development_dependency 'rake', ['>= 0']
26
- s.add_development_dependency 'test-unit', ['>= 0']
24
+ s.add_development_dependency "rubocop", [">= 0"]
25
+ s.add_development_dependency "rake", [">= 0"]
26
+ s.add_development_dependency "test-unit", [">= 0"]
27
+ s.add_development_dependency "thor", ["~> 0"]
28
+ s.add_development_dependency "mocha", ["~> 1.1.0"]
27
29
  end
@@ -0,0 +1,31 @@
1
+ require "test/unit"
2
+ require "mocha/test_unit"
3
+
4
+ require "roger/cli"
5
+ require_relative "../lib/roger_jshint/generator.rb"
6
+
7
+ # Mock project
8
+ class Project
9
+ def path
10
+ "./"
11
+ end
12
+ end
13
+
14
+ # Linting plugin unit test
15
+ class GeneratorTest < Test::Unit::TestCase
16
+ # Check if tasks is added
17
+ def test_default_generator
18
+ assert_includes Roger::Cli::Generate.tasks, "jshint", "Task is loaded"
19
+ end
20
+
21
+ def test_create_file
22
+ file_name = "./.jshintrc"
23
+ Roger::Cli::Base.expects(:project).once.returns(Project.new)
24
+ cli = Roger::Cli::Generate.new
25
+ cli.invoke "jshint", [], ["-f"]
26
+ assert File.exist?(file_name), "After invoking the file is written"
27
+
28
+ # Unlink file
29
+ File.unlink file_name
30
+ end
31
+ end
data/test/lint_test.rb CHANGED
@@ -1,5 +1,5 @@
1
- require_relative '../lib/roger_jshint/lint.rb'
2
- require 'test/unit'
1
+ require_relative "../lib/roger_jshint/lint.rb"
2
+ require "test/unit"
3
3
 
4
4
  # Fake tester to pass into the linter plugin
5
5
  class TesterStub
@@ -14,7 +14,7 @@ class TesterStub
14
14
  end
15
15
 
16
16
  def get_files(_, _)
17
- ['test/data/test.js']
17
+ ["test/data/test.js"]
18
18
  end
19
19
  end
20
20
 
@@ -30,11 +30,13 @@ class LintTest < Test::Unit::TestCase
30
30
  faketester = TesterStub.new
31
31
 
32
32
  linter = RogerJsHint::Lint.new
33
- linter.call(faketester, {})
33
+ success = linter.call(faketester, {})
34
34
 
35
35
  messages = faketester.messages
36
36
  messages.shift
37
37
 
38
+ assert_equal(false, success)
39
+
38
40
  assert_equal(messages,
39
41
  ["test/data/test.js:0 0: Bad option: 'subsub'.",
40
42
  "test/data/test.js:1 1: 'x' is not defined.",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roger_jshint
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hans Krutzer
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-05-26 00:00:00.000000000 Z
12
+ date: 2015-07-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: roger
@@ -73,6 +73,34 @@ dependencies:
73
73
  - - '>='
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
+ - !ruby/object:Gem::Dependency
77
+ name: thor
78
+ requirement: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ type: :development
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ - !ruby/object:Gem::Dependency
91
+ name: mocha
92
+ requirement: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: 1.1.0
97
+ type: :development
98
+ prerelease: false
99
+ version_requirements: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ version: 1.1.0
76
104
  description: |2
77
105
  Lint JavaScript files from within Roger, using jshint.
78
106
  Will use .jshintrc.
@@ -88,16 +116,19 @@ files:
88
116
  - .rubocop.yml
89
117
  - .ruby-version
90
118
  - .travis.yml
119
+ - CHANGELOG.md
91
120
  - Gemfile
92
121
  - LICENSE
93
122
  - README.md
94
123
  - Rakefile
95
124
  - lib/roger_jshint.rb
125
+ - lib/roger_jshint/generator.rb
96
126
  - lib/roger_jshint/jsonreporter.js
97
127
  - lib/roger_jshint/lint.rb
98
128
  - roger_jshint.gemspec
99
129
  - test/data/jshintrc
100
130
  - test/data/test.js
131
+ - test/generator_test.rb
101
132
  - test/lint_test.rb
102
133
  homepage: https://github.com/digitpaint/roger_jshint
103
134
  licenses:
@@ -119,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
150
  version: '0'
120
151
  requirements: []
121
152
  rubyforge_project:
122
- rubygems_version: 2.4.5
153
+ rubygems_version: 2.2.2
123
154
  signing_key:
124
155
  specification_version: 4
125
156
  summary: Lint JavaScript files within Roger