banalize 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.
@@ -0,0 +1,58 @@
1
+ banalizer :should_use_set_nounset do
2
+
3
+
4
+ synopsis "Always use 'set -u' or 'set -o nounset' in scripts"
5
+ severity :gentle
6
+ style :bug
7
+
8
+ description <<EOF
9
+
10
+ Quote from: http://www.davidpashley.com/articles/writing-robust-shell-scripts.html
11
+
12
+ Use set -u
13
+ ===========
14
+
15
+ How often have you written a script that broke because a variable
16
+ wasn't set? I know I have, many times.
17
+
18
+ chroot=$1
19
+ ...
20
+ rm -rf $chroot/usr/share/doc
21
+
22
+ If you ran the script above and accidentally forgot to give a
23
+ parameter, you would have just deleted all of your system
24
+ documentation rather than making a smaller chroot. So what can you
25
+ do about it? Fortunately bash provides you with set -u, which will
26
+ exit your script if you try to use an uninitialised variable. You
27
+ can also use the slightly more readable set -o nounset.
28
+
29
+ % bash /tmp/shrink-chroot.sh
30
+ $chroot=
31
+ david% bash -u /tmp/shrink-chroot.sh
32
+ /tmp/shrink-chroot.sh: line 3: $1: unbound variable
33
+ david%
34
+
35
+ EOF
36
+
37
+ def run
38
+ ret = true
39
+ #
40
+ # Prohibit using set +e option
41
+ #
42
+ errors.add "Setting +u option in shebang: #{shebang}" if (shebang.has? /\+u/)
43
+
44
+ if code.has? /set\s+\+u/
45
+ errors.add "Use of +u to unset -u option. Lines: #{code.lines}"
46
+ errors.add " #{code.search.inspect}"
47
+ end
48
+
49
+
50
+ if ( code.dont_have?(/set\s+-u/) ||
51
+ code.dont_have?(/set\s+-o\s+nounset/)) &&
52
+ shebang.dont_have?(/\s-u/)
53
+ errors.add "Can not find option -u or -o nounset anywhere in the script"
54
+ end
55
+ return errors.empty?
56
+ end
57
+
58
+ end
@@ -0,0 +1,40 @@
1
+ banalizer File.basename(__FILE__, '.rb').to_sym do
2
+
3
+ synopsis 'All lines must be indented accordingly to defined style'
4
+ severity :harsh
5
+ style :cosmetic
6
+
7
+ # Can be either :tabs or :spaces. Can overwrite in custom style file.
8
+ default :style => :spaces
9
+
10
+ description <<EOF
11
+
12
+ When indenting the code, all leading line indents should use the same
13
+ character: either all SPACES or all TABS, specified by the indentation
14
+ style.
15
+
16
+ Indenation style can be set in personal style file. Set it to :tabs or
17
+ :spaces. See CONFIGURATION.md for details.
18
+
19
+ EOF
20
+
21
+
22
+ def run
23
+
24
+ rex = case default[:style]
25
+ when :tabs
26
+ %r{^\s* }
27
+ when :spaces
28
+ %r{^\s*\t}
29
+ end
30
+
31
+ if code.has? rex
32
+ errors.add "Impoperly indented code. Current style is #{default[:style].to_s.upcase}"
33
+ errors.add " Badly indented lines: #{code.lines}"
34
+ end
35
+
36
+
37
+ return errors.empty?
38
+ end
39
+
40
+ end
@@ -0,0 +1,43 @@
1
+ banalizer :max_line_length do
2
+
3
+ synopsis 'The line length must not exceed max number of characters'
4
+ severity :brutal
5
+ style :cosmetic
6
+
7
+ default :max => 88 # Default can be overwritten by personal styles
8
+ # file
9
+
10
+ description <<EOF
11
+
12
+ Bash Style Guide and Coding Standard
13
+ ====================================
14
+
15
+ 1 Length of line
16
+
17
+ The total length of a line (including comment) must not exceed more
18
+ than 88 characters. Thus searching in cross direction can be avoided
19
+ and the file can be printed with the usual width of paper without
20
+ lines being cut or line breaks. Instructions have to be split up, as
21
+ applicable, texts can be made up as well.
22
+
23
+ Ref.: http://lug.fh-swf.de/vim/vim-bash/StyleGuideShell.en.pdf
24
+
25
+ EOF
26
+
27
+
28
+ def run
29
+ ret = true
30
+
31
+ offset = shebang ? 2 : 1 # Offset for line numbers,
32
+
33
+ lines.each_index do |idx|
34
+ len = lines[idx].length
35
+ errors.add(
36
+ "Line # #{idx + offset} is #{len} characters long, expected to be #{default[:max]} char. max."
37
+ ) if len > default[:max]
38
+ end
39
+
40
+ return errors.empty?
41
+ end
42
+
43
+ end
@@ -0,0 +1,26 @@
1
+ #!/bin/bash
2
+ set -e
3
+ set -u
4
+
5
+ ARG=${1:-unset}
6
+
7
+ case $ARG in
8
+ config)
9
+ cat <<EOF
10
+ ---
11
+ severity: 5
12
+ synopsis: Bash syntax check
13
+ description: |
14
+ This policy runs syntax check using 'bash -n' option.
15
+
16
+ EOF
17
+ exit 0;;
18
+ esac
19
+
20
+
21
+ [ -z "$ARG" ] && { echo "File name must be provided"; exit 64; }
22
+ [ -f "$ARG" ] || { echo "File must exist"; exit 64; }
23
+
24
+
25
+ \bash -n $ARG 2>&1
26
+ exit $?
@@ -0,0 +1,15 @@
1
+ banalizer :shebang_format do
2
+
3
+ description 'Format of shebang should be #!/usr/bin/env bash'
4
+
5
+ parser :bash
6
+
7
+ def run
8
+ unless shebang.has?(%r{\#!/usr/bin/env\s+bash})
9
+ errors.add "Expected first line to be '#!/usr/bin/env bash'"
10
+ errors.add " Shebang line is '#{shebang.to_s}'"
11
+ end
12
+ return errors.empty?
13
+ end
14
+
15
+ end
@@ -0,0 +1,16 @@
1
+ banalizer File.basename(__FILE__, '.rb').to_sym do
2
+
3
+ synopsis 'Code lines should not have spaces or tabs at the end'
4
+ severity :harsh
5
+ style :cosmetic
6
+
7
+ def run
8
+
9
+ if code.has?(/\s$/)
10
+ errors.add "Trailing spaces at the end of lines: #{code.lines}"
11
+ end
12
+
13
+ return errors.empty?
14
+ end
15
+
16
+ end
@@ -0,0 +1 @@
1
+ 0.0.1
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: banalize
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Dmytro Kovalov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-03-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rdoc
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: aruba
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: gli
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 2.5.4
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 2.5.4
69
+ description: Run policies tests on bash scripts and libraries with specified policies
70
+ and severity
71
+ email: dmytro.kovalov@gmail.com
72
+ executables:
73
+ - banalize
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - bin/banalize
78
+ - version.txt
79
+ - PARSER.md
80
+ - README.md
81
+ - ./lib/banalize/errors.rb
82
+ - ./lib/banalize/exception.rb
83
+ - ./lib/banalize/files.rb
84
+ - ./lib/banalize/parser/numbered.rb
85
+ - ./lib/banalize/parser.rb
86
+ - ./lib/banalize/policy/severity.rb
87
+ - ./lib/banalize/policy.rb
88
+ - ./lib/banalize/registry.rb
89
+ - ./lib/banalize/runner.rb
90
+ - ./lib/banalize.rb
91
+ - ./lib/commands/describe.rb
92
+ - ./lib/commands/dir.rb
93
+ - ./lib/commands/file.rb
94
+ - ./lib/commands/list.rb
95
+ - ./lib/core_extensions/string.rb
96
+ - ./lib/helpers/beautify.rb
97
+ - ./lib/policies/consistent_indents.rb
98
+ - ./lib/policies/define_path.rb
99
+ - ./lib/policies/exit_on_error.rb
100
+ - ./lib/policies/exit_on_unset_variable.rb
101
+ - ./lib/policies/indentation_style.rb
102
+ - ./lib/policies/max_line_length.rb
103
+ - ./lib/policies/shebang_format.rb
104
+ - ./lib/policies/trailing_spaces.rb
105
+ - ./lib/policies/minus_n_syntax_check
106
+ homepage: http://wizcorp.jp
107
+ licenses: []
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options:
111
+ - --title
112
+ - Banalize
113
+ - --main
114
+ - README.md
115
+ - -ri
116
+ require_paths:
117
+ - lib
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - '>='
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - '>='
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ requirements: []
130
+ rubyforge_project:
131
+ rubygems_version: 2.0.3
132
+ signing_key:
133
+ specification_version: 4
134
+ summary: Static syntax analyzer for Bash
135
+ test_files: []
136
+ has_rdoc: true