syntaxer 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+
5
+ script: "bundle exec rake spec && bundle exec cucumber"
data/Gemfile CHANGED
@@ -6,6 +6,8 @@ gem "git"
6
6
  #for colorizing output
7
7
  gem "rainbow"
8
8
  gem "progress_bar"
9
+ gem "jslint_on_rails", ">= 1.0.6"
10
+ gem "highline"
9
11
 
10
12
  group :development do
11
13
  gem "rspec", ">= 2.5.0"
@@ -26,6 +26,7 @@ GEM
26
26
  bundler (~> 1.0.0)
27
27
  git (>= 1.2.5)
28
28
  rake
29
+ jslint_on_rails (1.0.6)
29
30
  json (1.5.1)
30
31
  options (2.3.0)
31
32
  fattr
@@ -52,7 +53,9 @@ DEPENDENCIES
52
53
  aruba
53
54
  cucumber
54
55
  git
56
+ highline
55
57
  jeweler (~> 1.5.2)
58
+ jslint_on_rails (>= 1.0.6)
56
59
  progress_bar
57
60
  rainbow
58
61
  rspec (>= 2.5.0)
@@ -1,64 +1,97 @@
1
- = syntaxer
1
+ # syntaxer
2
2
 
3
- == Overview
3
+ [![Build Status](http://travis-ci.org/artemk/syntaxer.png)](http://travis-ci.org/artemk/syntaxer)
4
4
 
5
- Syntaxer make possible check syntax of scripts. It may be used in standalone mode and with git repository for checking changed and added files only.
5
+ ## Overview
6
+
7
+ Syntaxer is a gem that gives ability to check syntax of all files in your project at once. It may be used in standalone mode and with git repository for checking changed and added files only.
6
8
  It is useful for for rails team, because you need to store only file with rules, and git hook will be generated for you.
7
9
 
8
- == Installation
10
+ ## Installation
9
11
 
10
12
  To install syntaxer run
11
13
 
14
+ <pre><code>
12
15
  [sudo] gem install syntaxer
16
+ </code></pre>
13
17
 
14
-
15
- == Usage with rails
18
+ ## Usage with rails
16
19
 
17
20
  1) Add to Gemfile
18
21
 
19
- gem "syntaxer"
20
-
22
+ <pre><code>
23
+ gem "syntaxer"
24
+ </code></pre>
25
+
21
26
  2)
22
27
 
23
- bundle install
28
+ <pre><code>
29
+ bundle install
30
+ </code></pre>
24
31
 
25
32
  3)
26
33
 
34
+ <pre><code>
27
35
  rake syntaxer:install
36
+ </code></pre>
28
37
 
29
- It creates config/syntaxer.rb file with common rails options, you may edit it as you wish, and .git/hooks/pre-commit script, which will run syntax checking before every commit.
38
+ or run in working dir
30
39
 
31
- == Standalone usage
40
+ <pre><code>
41
+ syntaxer --install
42
+ </code></pre>
43
+
44
+ This command will run wizard which help you to decide which languages and files should be processed using syntaxer.
45
+
46
+ At final it will create config/syntaxer.rb file with common rails options, you may edit it as you wish, and .git/hooks/pre-commit script, which will run syntax checking before every commit.
47
+
48
+ ## Standalone usage (w/o Rails)
32
49
 
33
50
  Example of usage:
34
51
 
35
52
  Run syntax checking in current directory recursively
36
53
 
54
+ <pre><code>
37
55
  syntaxer
56
+ </code></pre>
38
57
 
39
58
  Run syntax checking in another directory recursively. Make sure to add '/' at the end.
40
59
 
60
+ <pre><code>
41
61
  syntaxer -p ./developement/
62
+ </code></pre>
42
63
 
43
64
  Install hook to git repository in current directory
44
65
 
45
- syntaxer -i -r git
66
+ <pre><code>
67
+ syntaxer -g -r git
68
+ </code></pre>
46
69
 
47
- Indicate custom config file
70
+ If you want to use custom config in pair with git
48
71
 
49
- syntaxer -c config.rb
72
+ <pre><code>
73
+ syntaxer -g -r git -c [CONFIG_FILE]
74
+ </code></pre>
50
75
 
76
+ Run syntaxer with custom config file
77
+
78
+ <pre><code>
79
+ syntaxer -c config.rb
80
+ </code></pre>
51
81
 
52
82
  Example of syntaxer.rb file:
53
83
 
84
+ <pre><code>
54
85
  syntaxer do
55
86
  languages :ruby, :haml, :sass do # type of files to be watched
56
87
  folders 'app/**/*', 'lib/**/*' # folders to be checked
57
88
  end
58
89
  end
90
+ </code></pre>
59
91
 
60
92
  You can specify multiple rules, for example you want to check only ruby files in app/controllers/* and only haml in app/views/*, you can write the next in your "initializers/syntaxer.rb" file:
61
93
 
94
+ <pre><code>
62
95
  syntaxer do
63
96
  languages :ruby do
64
97
  folders 'app/controllers/*'
@@ -75,22 +108,32 @@ You can specify multiple rules, for example you want to check only ruby files in
75
108
 
76
109
  ignore_folders 'app/models/**' # this folders will be deleted from all languages
77
110
  end
78
-
111
+ </code></pre>
79
112
 
80
113
  Languages available for now are: ruby, erb, haml, sass. You can extend this by your own, how to do that will be described below.
81
114
 
82
115
 
116
+ <pre><code>
83
117
  Options for usage
118
+ -i, --install run install wizzard, preferred method of installation
84
119
  -c, --config specify config file
85
120
  -p, --path path for syntax check. If this option is not specify it checks files from current directory
86
121
  -r, --repo indicate type of repository. Available git and svn at this time.
87
- -i, --install generates pre-commit hook and put it in .git/hooks folder. It checks syntax of languages what are indicated in options file before every commit
122
+ -g, --generate generates pre-commit hook and put it in .git/hooks folder. It checks syntax of languages what are indicated in options file before every commit
88
123
  -q, --quite disable information messages. Is needed when you only want to know the result: 1 or 0
89
124
  -l, --loud informate about every checked file
90
125
  -W, --warnings show warning messages
91
126
  -h, --help show help and options describe above.
127
+ </code></pre>
128
+
129
+ ## Syntaxer for javascript files
130
+
131
+ You may use syntaxer to check javascript files using jslint (http://github.com/psionides/jslint_on_rails)
132
+
133
+ Java and Rhino should be installed, you can read about it at jslint gem page.
134
+
92
135
 
93
- == Contributing to syntaxer
136
+ ## Contributing to syntaxer
94
137
 
95
138
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
96
139
  * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
@@ -100,24 +143,23 @@ Options for usage
100
143
  * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
101
144
  * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
102
145
 
103
- == TODO
146
+ ## TODO
104
147
 
105
148
  * Have to fix the problem with only created repository and initial commit with GIT repository
106
- * Add SVN support
107
149
  * Add description on how to add new languages
108
150
 
109
- == Known problems
151
+ ## Known problems
110
152
 
111
153
  * Git gem doesn't work properly on the very first commit.
112
154
 
113
- == Author
155
+ ## Author
114
156
 
115
157
  Artyom Kramarenko (artemk) Svitla Systems Inc (www.svitla.com)
116
158
 
117
- == Contributors
159
+ ## Contributors
118
160
 
119
161
  Artem Melnikov (ignar) Svitla Systems Inc (www.svitla.com)
120
162
 
121
- == Copyright
163
+ ## Copyright
122
164
 
123
165
  See LICENSE.txt for further details.
data/Rakefile CHANGED
@@ -35,6 +35,30 @@ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
35
  spec.rcov = true
36
36
  end
37
37
 
38
+ namespace :rcov do
39
+ desc "Run all specs on multiple ruby versions (requires rvm)"
40
+ task :portability do
41
+ %w{1.8.7 1.9.2}.each do |version|
42
+ system <<-BASH
43
+ bash -c 'if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then
44
+ source ~/.rvm/scripts/rvm;
45
+ rvm gemset list | grep syntaxer > /dev/null;
46
+ if [ $? -eq 1 ]; then
47
+ echo -e "\e[0;31m--------- Please run \033[4mrvm use #{version}@syntaxer --create; gem install bundler; bundle install;\033[0m\e[0;31m to create gemset for tests. Thanks. ----------\n\e[0m"
48
+ exit;
49
+ fi
50
+ rvm use #{version}@syntaxer;
51
+ echo -e "\e[0;33m--------- version #{version}@syntaxer ----------\n\e[0m";
52
+ rspec --color spec/*;
53
+ cucumber;
54
+ else
55
+ echo You have no rvm installed or it is installed not in home directory.
56
+ fi'
57
+ BASH
58
+ end
59
+ end
60
+ end
61
+
38
62
  task :default => :spec
39
63
 
40
64
  require 'yard'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.5.0
@@ -17,6 +17,9 @@ class SyntaxerCLI
17
17
  options.languages = :all
18
18
  options.warnings = false
19
19
  options.rails = false
20
+ options.jslint = false
21
+ options.wizzard = false
22
+ options.restore = false # restore git hook, internal gem option
20
23
 
21
24
  opts = OptionParser.new do |opts|
22
25
  opts.banner = "Usage: syntaxer [options]"
@@ -50,7 +53,7 @@ class SyntaxerCLI
50
53
  options.loud = true
51
54
  end
52
55
 
53
- opts.on("-i", "--install", "Write hooks to git") do |r|
56
+ opts.on("-g", "--generate", "Write hooks to git") do |r|
54
57
  options.generate = true
55
58
  end
56
59
 
@@ -66,6 +69,16 @@ class SyntaxerCLI
66
69
  options.rails = true
67
70
  end
68
71
 
72
+ opts.on("-j", "--jslint [DIR]", String, "Run jslint") do |r|
73
+ raise OptionParser::MissingArgument if r.nil?
74
+ r = r+'/' unless r =~ /\/$/
75
+ options.jslint = r
76
+ end
77
+
78
+ opts.on("-i", "--install", "Run wizzard") do
79
+ options.wizzard = true
80
+ end
81
+
69
82
  opts.separator ""
70
83
  opts.separator "Common options:"
71
84
 
@@ -80,14 +93,21 @@ class SyntaxerCLI
80
93
  end
81
94
  end
82
95
 
83
- opts.parse!(args)
96
+ begin
97
+ opts.parse!(args)
98
+ rescue
99
+ puts opts
100
+ raise
101
+ end
84
102
  options
85
103
  end
86
104
 
87
105
  end
88
106
 
89
107
  options = SyntaxerCLI.parse(ARGV)
90
- if options.generate.nil?
108
+ if options.wizzard
109
+ Syntaxer.wizzard(options)
110
+ elsif options.generate.nil?
91
111
  Syntaxer.check_syntax(options.instance_variable_get("@table"))
92
112
  else
93
113
  Syntaxer.make_hook(options.instance_variable_get("@table"))
@@ -12,3 +12,22 @@ Feature: Check syntax in plain mode
12
12
  Then the exit status should not be 0
13
13
  And the output should not contain "Syntax OK"
14
14
 
15
+ @plain @jslint
16
+ Scenario: Run checker in directory with jslint and wrong rubies
17
+ Given a file named "correct.rb" with:
18
+ """
19
+ class A;end
20
+ """
21
+ And a file named "wrong.rb" with:
22
+ """
23
+ class B
24
+ """
25
+ And a file named "javascripts/correct.js" with:
26
+ """
27
+ var func = function(){};
28
+ """
29
+ And a file named "javascripts/wrong.js" with:
30
+ """
31
+ var func = function(){
32
+ """
33
+ When I run 'syntaxer --jslint ./' and jslint should be invoked
@@ -9,4 +9,16 @@ Feature: Check git repository before commit
9
9
  When I run `git commit -m "some message"`
10
10
  Then the syntaxer shoud stop commit
11
11
  And the output should contain "Errors:"
12
+
13
+ @repo @rails @jslint
14
+ Scenario: Installation hook in rails environment with jslint feature
15
+ Given rails project with js scripts
16
+ And some lib with wrong syntax
17
+ And some js script
18
+ And installed hook in rails context with jslint
19
+ When I run `git commit -m "some message"`
20
+ Then the syntaxer shoud stop commit
21
+ And the output should contain "Running JSLint:"
22
+ And the output should contain "jslint checking failed"
23
+ And the output should contain "Errors:"
12
24
  And the output should contain "EE"
@@ -11,7 +11,3 @@ Feature: Check git repository before commit
11
11
  And some file with wrong syntax
12
12
  When run `git commit -m "some message"` interactively
13
13
  Then the syntaxer should stop commit
14
-
15
-
16
-
17
-
@@ -7,20 +7,30 @@ Given /^directory contains two files$/ do
7
7
  create_temp_plain_work_dir
8
8
  end
9
9
 
10
- When /^I run 'syntaxer'$/ do
11
- run_simple(unescape("#{File.join(File.dirname(__FILE__),'..','..','bin','syntaxer')}"), false)
10
+ Then /^I run 'syntaxer([^']*)'$/ do |arg|
11
+ run_simple(unescape("#{File.join(File.dirname(__FILE__),'..','..','bin','syntaxer')} #{arg}"), false)
12
12
  end
13
13
 
14
- Then /^I run 'syntaxer \-l'$/ do
15
- run_simple(unescape("#{File.join(File.dirname(__FILE__),'..','..','bin','syntaxer')} -l"), false)
16
- end
14
+ When /^I run 'syntaxer \-\-jslint \.\/' and jslint should be invoked$/ do
15
+ options = OpenStruct.new()
16
+ options.restore = false
17
+ options.languages = :all
18
+ options.jslint = './'
19
+ options.config_file = Syntaxer::SYNTAXER_RULES_FILE
20
+ options.root_path = '.'
17
21
 
18
- Then /^I run 'syntaxer \-W'$/ do
19
- run_simple(unescape("#{File.join(File.dirname(__FILE__),'..','..','bin','syntaxer')} -W"), false)
20
- end
22
+ Syntaxer::Printer.stub(:print_result)
23
+
24
+ reader = double
25
+ reader.stub(:add_rule)
26
+ Syntaxer::Reader::DSLReader.stub(:load){reader}
21
27
 
22
- Then /^I run 'syntaxer \-v'$/ do
23
- run_simple(unescape("#{File.join(File.dirname(__FILE__),'..','..','bin','syntaxer')} -v"), false)
28
+ checker = double
29
+ checker.stub(:error_files){[]}
30
+ Syntaxer::Runner.should_receive(:javascript).and_return(Proc.new{})
31
+ Syntaxer::Checker.stub(:process){checker}
32
+
33
+ Syntaxer.check_syntax(options.instance_variable_get("@table"))
24
34
  end
25
35
 
26
36
  When /^I cd to working directory$/ do
@@ -9,20 +9,41 @@ Given /^rails project$/ do
9
9
  run_simple(unescape("git commit -m'first commit'"), false)
10
10
  end
11
11
 
12
+ Given /^rails project with js scripts$/ do
13
+ in_current_dir do
14
+ FileUtils.mkdir_p("public/scripts")
15
+ end
16
+ Given "rails project"
17
+ end
18
+
19
+
12
20
  Given /^some lib with wrong syntax$/ do
13
21
  write_file('lib/wrong.rb', "mod A;end")
14
22
  write_file('app/wrong.rb', "mod A;end")
15
23
  run_simple(unescape("git add ."), false)
16
24
  end
17
25
 
26
+ Given /^some js script$/ do
27
+ write_file('public/javascripts/main.js', "var func = function(){")
28
+ run_simple(unescape("git add ."), false)
29
+ end
30
+
18
31
  Given /^installed hook in rails context$/ do
19
- run_simple("#{File.join(File.dirname(__FILE__),'..','..','bin','syntaxer')} -i -r git --hook --rails")
32
+ run_simple("#{File.join(File.dirname(__FILE__),'..','..','bin','syntaxer')} -g -r git --hook --rails")
20
33
  in_current_dir do
21
34
  FileUtils.cp(File.join(File.dirname(__FILE__),'..','..',"syntaxer_rails_rules.dist.rb"),"config/syntaxer.rb")
22
35
  end
23
36
  run_simple('chmod 755 .git/hooks/pre-commit')
24
37
  end
25
38
 
39
+ Given /^installed hook in rails context with jslint$/ do
40
+ Given "installed hook in rails context"
41
+ in_current_dir do
42
+ FileUtils.cp(File.join(File.dirname(__FILE__),'..','..',"syntaxer_rails_rules_jslint.dist.rb"),"config/syntaxer.rb")
43
+ end
44
+ run_simple('chmod 755 .git/hooks/pre-commit')
45
+ end
46
+
26
47
  Then /^the syntaxer shoud stop commit$/ do
27
48
  @last_exit_status.should eql(1)
28
49
  end
@@ -12,8 +12,8 @@ When /^run `git commit \-m \"some message\"` interactively$/ do
12
12
  add_hook
13
13
  end
14
14
 
15
- Then /^I run 'syntaxer \-i \-r git'$/ do
16
- run_simple(unescape("#{File.join(File.dirname(__FILE__),'..','..','bin','syntaxer')} -i -r git"), false)
15
+ Then /^I run 'syntaxer \-g \-r git'$/ do
16
+ run_simple(unescape("#{File.join(File.dirname(__FILE__),'..','..','bin','syntaxer')} -g -r git"), false)
17
17
  end
18
18
 
19
19