pretty 0.2 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/bin/pretty +50 -53
  2. metadata +3 -2
data/bin/pretty CHANGED
@@ -5,58 +5,55 @@
5
5
 
6
6
  #checking for filename(s)
7
7
  if ARGV.empty?
8
- STDERR.puts "ERROR: Give filename(s) as argument(s)"
8
+ STDERR.puts "Usage: pretty [-language] filename(-s)\nIf not language specified rules for Ruby will be used.\nExample pretty hello.rb"
9
9
  else
10
- #declaring variables
11
- errors = []
12
- ln_cnt = 1
13
- err_cnt = 0
14
-
15
- #parsing each file
16
- ARGV.each do |filename|
17
-
18
- file = File.open(filename)
19
-
20
- #check for shebang
21
- if file.readline[0..1] != "#!"
22
- errors[err_cnt] = "#{filename}:#{ln_cnt}: No shebang found but it's not end of world ;-)"
23
- err_cnt+=1
24
- end
25
-
26
- #now checking for rest errors
27
- file.rewind
28
- file.each_line do |line|
29
- ln_cnt+=1
30
- if line.size > 80 #short lines are better to read
31
- errors[err_cnt] = "#{filename}:#{ln_cnt}: Too long line"
32
- err_cnt+=1
33
- end
34
- if line =~ /^;/ #it's not good to add ; on end of line
35
- errors[err_cnt] = "#{filename}:#{ln_cnt}: You don't need to use ; on line end"
36
- err_cnt+=1
37
- end
38
- if line =~ /\t{4}/ #code with less tabulations is better to read
39
- errors[err_cnt] = "#{filename}:#{ln_cnt}: Too many tabulations"
40
- err_cnt+=1
41
- end
42
- if line =~ /[$]\w+/ #it's not good to use global variables
43
- errors[err_cnt] = "#{filename}:#{ln_cnt}: It's not good to use global variables.\
44
- \nIgnore it if you are using $_ or another special variable"
45
- err_cnt+=1
46
- end
47
- end
48
-
49
- file.close
50
- ln_cnt = 1
51
-
52
- end
53
-
54
- #shows and save report
55
- name = "report#{Time.now.to_i}.txt"
56
- file = File.open(name,"w")
57
- p "Found #{err_cnt} errors in #{ARGV.size} files"
58
- if err_cnt == 0 : p "This is propably the best program in the world!" end
59
- errors.each {|err| p err; file << (err+"\n")}
60
- p "Report file: #{name}"
61
- file.close
10
+ #declaring variables
11
+ errors = []
12
+ ln_cnt = 1
13
+ err_cnt = 0
14
+ rules = []
15
+
16
+ #checking for language of file(-s)
17
+ if ARGV[0] =~ /-/
18
+ language = ARGV.shift[1..-1]
19
+ end
20
+
21
+ if !language : language = "ruby" end
22
+ File.open("./rules/#{language}.txt","r").read.each {|line| rules << line.split("!!!")}
23
+
24
+ ARGV.each do |filename| #parsing file(-s)
25
+
26
+ file = File.open(filename)
27
+
28
+ #check for shebang
29
+ if file.readline[0..1] != "#!"
30
+ errors[err_cnt] = "#{filename}:#{ln_cnt}: No shebang found but it's not end of world ;-)"
31
+ err_cnt+=1
32
+ end
33
+
34
+ #now checking for rest errors
35
+ file.rewind
36
+ file.each_line do |line|
37
+ ln_cnt+=1
38
+ rules.each do |rule|
39
+ if eval(rule[0])
40
+ errors[err_cnt] = "#{filename}:#{ln_cnt}: #{rule[1]}"
41
+ err_cnt+=1
42
+ end
43
+ end
44
+ end
45
+
46
+ file.close
47
+ ln_cnt = 1
48
+
49
+ end
50
+
51
+ #shows and save report
52
+ name = "report#{Time.now.to_i}.txt"
53
+ file = File.open(name,"w")
54
+ puts "Found #{err_cnt} errors in #{ARGV.size} files"
55
+ if err_cnt == 0 : puts "This is propably the best program in the world!" end
56
+ errors.each {|err| puts err; file << (err+"\n")}
57
+ puts "Report file: #{name}"
58
+ file.close
62
59
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pretty
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.2"
4
+ version: "0.3"
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mateusz 'WujcioL' Tybura
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-08-12 00:00:00 +02:00
12
+ date: 2008-08-19 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -24,6 +24,7 @@ extra_rdoc_files: []
24
24
  files:
25
25
  - ./bin/pretty
26
26
  - ./bin/pretty.bat
27
+ - ./bin/rules
27
28
  has_rdoc: false
28
29
  homepage: http://wujciol.yoyo.pl
29
30
  post_install_message: