cowl 0.5 → 0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (7) hide show
  1. checksums.yaml +4 -4
  2. data/CONFIGURE.md +1 -1
  3. data/README.md +27 -25
  4. data/bin/cowl +22 -95
  5. data/lib/cowl.rb +61 -41
  6. data/lib/version.rb +1 -1
  7. metadata +17 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d415ce09daf37251429ae3953e415cde9bfdbbd3
4
- data.tar.gz: 95847e09b6e320df61230f6ef38010ac3d616bac
3
+ metadata.gz: f4c8fcb9be685e11e164c6fafa86fe354eba6714
4
+ data.tar.gz: 6c8b6e63914a308fc77da6423f9b1e2a38f4e5a0
5
5
  SHA512:
6
- metadata.gz: a4720ae08bf1a4d6b6a5230114edd4f667348b6edde8c58f68febdb9fe82a29c485212d725e9d1b3dd455fb1aec22480b1b166a1b66c402a3ae79b0774249bff
7
- data.tar.gz: 3bfade1de48b7de81dfbc0a1c0d0f57754f67985d8b0d5f49210badc2b2aec9d601c55704cfe0c4d2fbad5c44689ca53a2eb4ad1f7c9385699643b320aac6d17
6
+ metadata.gz: a2663c5811b77a77bb346337ec43e48974b9073dc18a997f9261fe6c7629f71b1676989a1f73a2be3c52dcccd10db08359a7441a92bf2cedc1dbbd66e2b19635
7
+ data.tar.gz: b84ce5aa9cff6f05194c397c36498b087913dc98b63005694031135a0ab3189ac851ca292fba3b14a5a034cb9ee259c7fdb779c5bb31c906d911c87bf3b2faff
@@ -15,7 +15,7 @@ Run `cowl -h` or `cowl --help` for a full list, or refer to the source code for
15
15
  ```
16
16
  $ cowl -h
17
17
  Usage: cowl [options] [<files>]
18
- -i, --ignore pattern Ignore file names matching Ruby regex pattern
18
+ -i, --ignore pattern Ignore file patterns (fnmatch)
19
19
  -w, --max-width= Maximum column width, either an integer or "unlimited". Default: 80
20
20
  -h, --help Print usage info
21
21
  -v, --version Print version info
data/README.md CHANGED
@@ -1,25 +1,8 @@
1
1
  # cowl - column width linter
2
2
 
3
- # HOMEPAGE
3
+ `cowl` helps you keep your source code / text in a terminal-friendly 80-column width.
4
4
 
5
- https://github.com/mcandre/cowl
6
-
7
- # RUBYGEMS
8
-
9
- https://rubygems.org/gems/cowl
10
-
11
- # ABOUT
12
-
13
- Cowl is a command line program for identifying text lines that are considered too long, wider than the conventional column width `80` or so.
14
-
15
- cowl is a shell wrapper around the traditional GNU [grep](http://www.gnu.org/software/grep/) backend, presenting a frontend similar to modern linters like [Reek](https://github.com/troessner/reek/wiki) and [JSHint](http://jshint.com/).
16
-
17
- * Recursive file search by default
18
- * Optional ignore patterns
19
- * Configuration via per-project and per-user [dotfiles](https://github.com/mcandre/cowl/blob/master/CONFIGURE.md#dotfiles)
20
- * Install via a standard programming language package manager
21
-
22
- # EXAMPLE
5
+ # EXAMPLES
23
6
 
24
7
  ```
25
8
  $ cowl examples/
@@ -28,26 +11,45 @@ examples/hello.bf:3:++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++
28
11
  $ cat examples/hello.bf | cowl
29
12
  stdin:3:++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.
30
13
 
31
- $ wc -L examples/hello.bf
32
- 106 examples/hello.bf
14
+ $ wc -c examples/hello.bf
15
+ 158 examples/hello.bf
33
16
 
34
- $ cowl -w 106 examples/
17
+ $ cowl -w 160 examples/hello.bf
35
18
  $
36
19
 
37
- $ cowl -i .bf examples/
20
+ $ cowl -i '*.bf' examples/
38
21
  $
39
22
 
40
23
  $ cowl -h
41
24
  Usage: cowl [options] [<files>|-]
42
- -i, --ignore pattern Ignore file names matching Ruby regex pattern
25
+ -i, --ignore pattern Ignore file patterns (fnmatch)
43
26
  -w, --max-width= Maximum column width, either an integer or "unlimited". Default: 80
44
27
  -h, --help Print usage info
45
28
  -v, --version Print version info
46
29
  ```
47
30
 
31
+ # HOMEPAGE
32
+
33
+ https://github.com/mcandre/cowl
34
+
35
+ # RUBYGEMS
36
+
37
+ https://rubygems.org/gems/cowl
38
+
39
+ # ABOUT
40
+
41
+ Cowl is a command line program for identifying text lines that are considered too long, wider than the conventional column width `80` or so.
42
+
43
+ cowl is a shell wrapper around the traditional GNU [grep](http://www.gnu.org/software/grep/) backend, presenting a frontend similar to modern linters like [Reek](https://github.com/troessner/reek/wiki) and [JSHint](http://jshint.com/).
44
+
45
+ * Recursive file scanning, like `jshint .`
46
+ * Optional ignore patterns, like `.gitignore`
47
+ * Configuration via per-project and per-user [dotfiles](https://github.com/mcandre/cowl/blob/master/CONFIGURE.md#dotfiles)
48
+ * Install via a standard programming language package manager
49
+
48
50
  # REQUIREMENTS
49
51
 
50
- * [Ruby](https://www.ruby-lang.org/) 2+
52
+ * [Ruby](https://www.ruby-lang.org/) 2.0+
51
53
  * [grep](http://www.gnu.org/software/grep/) (often built-in, or provided by [git](http://git-scm.com/))
52
54
 
53
55
  E.g., Windows users can `chocolatey install git`.
data/bin/cowl CHANGED
@@ -3,28 +3,24 @@
3
3
  require 'rubygems'
4
4
  require 'find'
5
5
  require 'optparse'
6
+ require 'dotsmack'
6
7
  require 'yaml'
7
8
  require 'cowl'
8
9
 
9
- IGNORE_FILENAME = '.cowlignore'
10
- CONFIGURATION_FILENAME = '.cowlrc.yml'
11
-
12
10
  def main
13
11
  ignores = DEFAULT_IGNORES
14
12
 
15
- filenames = ['-']
16
-
17
13
  configuration_flags = {}
18
14
 
19
15
  option = OptionParser.new do |option|
20
16
  option.banner = "Usage: cowl [options] [<files>|-]"
21
17
 
22
- option.on('-i', '--ignore pattern', 'Ignore file names matching Ruby regex pattern') do |pattern|
18
+ option.on('-i', '--ignore pattern', 'Ignore file patterns (fnmatch)') do |pattern|
23
19
  ignores << pattern
24
20
  end
25
21
 
26
22
  option.on('-w=', '--max-width', "Maximum column width, either an integer or \"unlimited\". Default: 80") do |max_width|
27
- configuration_flags["max_width"] = max_width
23
+ configuration_flags['max_width'] = max_width
28
24
  end
29
25
 
30
26
  option.on('-h', '--help', 'Print usage info') do
@@ -40,100 +36,31 @@ def main
40
36
 
41
37
  option.parse!
42
38
 
43
- filenames = ARGV unless ARGV.empty?
44
-
45
- if filenames.empty? || filenames == ['-'] then
46
- configuration_dotfile = DEFAULT_CONFIGURATION
47
-
48
- pwd = Dir.pwd
49
-
50
- dir = pwd
51
-
52
- parent_of_home = File.expand_path("..", ENV["HOME"])
53
-
54
- while dir != parent_of_home
55
- ignore_file = dir + File::SEPARATOR + IGNORE_FILENAME
56
-
57
- if File.exist?(ignore_file) then
58
- ignores.concat(open(ignore_file).read.split("\n"))
59
- end
60
-
61
- dir = File.expand_path("..", dir)
39
+ filenames =
40
+ if ARGV == []
41
+ ['-']
42
+ else
43
+ ARGV
62
44
  end
63
45
 
64
- if ignores.none? { |ignore| pwd =~ %r(#{ignore}) } then
65
- dir = Dir.pwd
66
-
67
- parent_of_home = File.expand_path("..", ENV["HOME"])
68
-
69
- while dir != parent_of_home
70
- config_file = dir + File::SEPARATOR + CONFIGURATION_FILENAME
71
-
72
- if File.exist?(config_file) then
73
- configuration_dotfile = DEFAULT_CONFIGURATION.merge(YAML.load_file(config_file))
74
- break
75
- else
76
- dir = File.expand_path("..", dir)
77
- end
78
- end
79
-
80
- # Command line flags override dotfile settings
81
- configuration = configuration_dotfile.merge(configuration_flags)
82
-
83
- check_stdin(configuration)
84
- end
85
- else
86
- recursive_filenames = []
46
+ dotsmack = Dotsmack::Smacker.new(
47
+ dotignore = '.cowlignore',
48
+ additional_ignores = ignores,
49
+ dotconfig = '.cowlrc.yml'
50
+ )
87
51
 
88
- filenames.each do |f|
89
- if File.directory? f
90
- recursive_filenames = recursive_filenames.concat(recursive_list(f, ignores))
52
+ dotsmack.enumerate(filenames).each do |filename, config|
53
+ config =
54
+ if config.nil?
55
+ configuration_flags
91
56
  else
92
- recursive_filenames << f
93
- end
94
- end
95
-
96
- configuration_dotfile = DEFAULT_CONFIGURATION
97
-
98
- recursive_filenames.each do |f|
99
- dir = File.expand_path("..", f)
100
-
101
- parent_of_home = File.expand_path("..", ENV["HOME"])
102
-
103
- while dir != parent_of_home
104
- ignore_file = dir + File::SEPARATOR + IGNORE_FILENAME
105
-
106
- if File.exist?(ignore_file) then
107
- ignores.concat(open(ignore_file).read.split("\n"))
108
- end
109
-
110
- dir = File.expand_path("..", dir)
57
+ YAML.load(config).merge(configuration_flags)
111
58
  end
112
59
 
113
- if ignores.none? { |ignore| f =~ %r(#{ignore}) } then
114
- dir = File.expand_path("..", f)
115
-
116
- parent_of_home = File.expand_path("..", ENV["HOME"])
117
-
118
- while dir != parent_of_home
119
- config_file = dir + File::SEPARATOR + CONFIGURATION_FILENAME
120
-
121
- if File.exist?(config_file) then
122
- configuration_dotfile = DEFAULT_CONFIGURATION.merge(YAML.load_file(config_file))
123
- break
124
- else
125
- dir = File.expand_path("..", dir)
126
- end
127
- end
128
-
129
- # Hack to Reset configuration when changing directories
130
- configuration_dotfile = DEFAULT_CONFIGURATION unless File.exist?(dir + File::SEPARATOR + CONFIGURATION_FILENAME)
131
-
132
- # Command line flags override dotfile settings
133
- configuration = configuration_dotfile.merge(configuration_flags)
134
-
135
- check(f, configuration)
136
- end
60
+ if filename == '-'
61
+ check_stdin(config)
62
+ else
63
+ check(filename, config)
137
64
  end
138
65
  end
139
66
  end
@@ -1,33 +1,52 @@
1
- require 'rubygems'
2
1
  require 'ptools'
3
2
  require 'tempfile'
4
3
 
5
- $stdout.sync = true
6
-
7
- require 'version'
4
+ require_relative 'version'
8
5
 
9
6
  DEFAULT_IGNORES = %w(
10
- tmp/
11
- \.hg/
12
- \.svn/
13
- \.git/
14
- \.git
15
- \.gitignore
16
- node_modules/
17
- bower_components/
18
- \.vagrant/
7
+ tmp
8
+ .hg
9
+ .svn
10
+ .git
11
+ .gitignore
12
+ node_modules
13
+ bower_components
14
+ target
15
+ dist
16
+ .vagrant
19
17
  Gemfile.lock
20
- \.exe
21
- \.bin
22
- \.app
23
- \.xcodeproj/
24
- \.dSYM/
25
- \.png
26
- \.jpg
27
- \.jpeg
28
- \.svg
29
- \.min.js
30
- -min.js
18
+ *.exe
19
+ *.bin
20
+ *.apk
21
+ *.ap_
22
+ res
23
+ *.dmg
24
+ *.pkg
25
+ *.app
26
+ *.xcodeproj
27
+ *.lproj
28
+ *.xcassets
29
+ *.pmdoc
30
+ *.dSYM
31
+ *.class
32
+ *.zip
33
+ *.jar
34
+ *.war
35
+ *.xpi
36
+ *.jad
37
+ *.cmo
38
+ *.cmi
39
+ *.png
40
+ *.gif
41
+ *.jpg
42
+ *.jpeg
43
+ *.tiff
44
+ *.ico
45
+ *.svg
46
+ *.dot
47
+ *.wav
48
+ *.mp3
49
+ *[.-]min.*
31
50
  )
32
51
 
33
52
  DEFAULT_MAX_WIDTH = 80
@@ -35,7 +54,7 @@ DEFAULT_MAX_WIDTH = 80
35
54
  UNLIMITED = 'unlimited'
36
55
 
37
56
  DEFAULT_CONFIGURATION = {
38
- "max_width" => DEFAULT_MAX_WIDTH
57
+ 'max_width' => DEFAULT_MAX_WIDTH
39
58
  }
40
59
 
41
60
  #
@@ -64,25 +83,19 @@ class Widening
64
83
  end
65
84
  end
66
85
 
67
- def self.recursive_list(directory, ignores = DEFAULT_IGNORES)
68
- Find.find(directory).reject do |f|
69
- File.directory?(f) ||
70
- ignores.any? { |ignore| f =~ %r(#{ignore}) } ||
71
-
72
- begin
73
- File.binary?(f)
74
- rescue Errno::ENOENT
75
- true
86
+ def self.check_stdin(configuration = nil)
87
+ configuration =
88
+ if configuration.nil?
89
+ DEFAULT_CONFIGURATION
90
+ else
91
+ configuration
76
92
  end
77
- end
78
- end
79
93
 
80
- def self.check_stdin(configuration = DEFAULT_CONFIGURATION)
81
- max_width = configuration["max_width"]
94
+ max_width = configuration['max_width']
82
95
 
83
96
  contents = $stdin.read
84
97
 
85
- t = Tempfile.new('aspelllint')
98
+ t = Tempfile.new('cowl')
86
99
  t.write(contents)
87
100
  t.close
88
101
 
@@ -99,8 +112,15 @@ def self.check_stdin(configuration = DEFAULT_CONFIGURATION)
99
112
  end
100
113
  end
101
114
 
102
- def self.check(filename, configuration = DEFAULT_CONFIGURATION)
103
- max_width = configuration["max_width"]
115
+ def self.check(filename, configuration = nil)
116
+ configuration =
117
+ if configuration.nil?
118
+ DEFAULT_CONFIGURATION
119
+ else
120
+ configuration
121
+ end
122
+
123
+ max_width = configuration['max_width']
104
124
 
105
125
  if max_width != UNLIMITED
106
126
  output = `grep -n \'^.\\{#{max_width.to_i + 1},\\}$\' \"#{filename}\"`
@@ -2,5 +2,5 @@
2
2
  # Cowl
3
3
  #
4
4
  module Cowl
5
- VERSION = '0.5'
5
+ VERSION = '0.6'
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cowl
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.5'
4
+ version: '0.6'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Pennebaker
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: dotsmack
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '0.3'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '0.3'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rake
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -245,7 +259,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
245
259
  requirements:
246
260
  - - '>='
247
261
  - !ruby/object:Gem::Version
248
- version: '0'
262
+ version: '2.0'
249
263
  required_rubygems_version: !ruby/object:Gem::Requirement
250
264
  requirements:
251
265
  - - '>='
@@ -253,7 +267,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
253
267
  version: '0'
254
268
  requirements: []
255
269
  rubyforge_project:
256
- rubygems_version: 2.2.2
270
+ rubygems_version: 2.4.6
257
271
  signing_key:
258
272
  specification_version: 4
259
273
  summary: column width linter