cowl 0.1 → 0.2

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.
Files changed (7) hide show
  1. checksums.yaml +4 -4
  2. data/CONFIGURE.md +50 -0
  3. data/README.md +85 -0
  4. data/bin/cowl +54 -15
  5. data/lib/cowl.rb +24 -9
  6. data/lib/version.rb +1 -1
  7. metadata +7 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1eeeaea54a13d739e017d255d4d621ac6230e521
4
- data.tar.gz: 98202af27c71039c0757da39ebc94e21b30339e8
3
+ metadata.gz: 436d01bac929781a14589af2137d683976216efd
4
+ data.tar.gz: 21b34be19ede64bfea48b8c1318d3ce644de4212
5
5
  SHA512:
6
- metadata.gz: 6e3461512a78c1c8d46044abe148276df37df975020a98e22a0b65836026535c951b266acf77417fcdcf0d4767a40c6cbe4b1e3878bbf234ad647ff562a8a026
7
- data.tar.gz: c0c6ab889dd8c5205faecf30cb517da6c86a04cc674ead45390ade986328f0a288d5ee73c71dccb7db15ef63f9297a73455d3160411f179615e4078c37ef86da
6
+ metadata.gz: 543230d30dff94fe4b73c722786835d2d426f225010f651eeec5afb4a49e452f6670587b2a041342db5a532a124917fccdd619262359cfa8ba749fe912992bac
7
+ data.tar.gz: 44ab04bc4bf5782135459ea0ba832de48081d03724f9f2cc0260991c840737aa2a709679e499c465db835e203070f377f478ddcbb6aafb3a7c83e410f9aa6c85
data/CONFIGURE.md ADDED
@@ -0,0 +1,50 @@
1
+ # Configuration
2
+
3
+ Cowl offers multiple ways to resolve preferences:
4
+
5
+ 1. Command-line flags (`cowl -i`, `cowl -w`)
6
+ 2. Dotfiles (`.cowlignore`, `.cowlrc.yml`)
7
+ 3. Built-in defaults (`DEFAULT_IGNORES`, `DEFAULT_MAX_WIDTH`)
8
+
9
+ Any command-line flags that are present override the same settings in dotfiles and built-in defaults.
10
+
11
+ # Command-line flags
12
+
13
+ Run `cowl -h` or `cowl --help` for a full list, or refer to the source code for `bin/cowl`.
14
+
15
+ ```
16
+ $ cowl -h
17
+ Usage: cowl [options] [<files>]
18
+ -i, --ignore pattern Ignore file names matching Ruby regex pattern
19
+ -w, --max-width= Maximum column width, either an integer or "unlimited". Default: 80
20
+ -h, --help Print usage info
21
+ -v, --version Print version info
22
+ ```
23
+
24
+ # Dotfiles
25
+
26
+ Cowl automatically applies any `.cowlignore` and/or `.cowlrc.yml` configuration files in the same directory as a file being scanned, or a parent directory (`../.cowlignore`, `../.cowlrc.yml`), up to `$HOME/.cowlignore`, `$HOME/.cowlrc.yml`, if any such files exist.
27
+
28
+ ## `.cowlignore`
29
+
30
+ Samples:
31
+
32
+ * [cowl/.cowlignore](https://github.com/mcandre/cowl/blob/master/.cowlignore)
33
+ * [examples/.cowlignore](https://github.com/mcandre/cowl/blob/master/examples/.cowlignore)
34
+
35
+ A `.cowlignore` may contain Ruby regex patterns of files and/or folders to exclude from scanning, one pattern per line.
36
+
37
+ ## `.cowlrc.yml`
38
+
39
+ Samples:
40
+
41
+ * [cowl/.cowlrc.yml](https://github.com/mcandre/cowl/blob/master/.cowlrc.yml)
42
+ * [unwrapped-books/.cowlrc.yml](https://github.com/mcandre/cowl/blob/master/examples/unwrapped-books/.cowlrc.yml)
43
+
44
+ `.cowlrc.yml` may contain a number of keys:
45
+
46
+ * `max_width` may be an integer (e.g. `80`), or `unlimited`.
47
+
48
+ # Built-in defaults
49
+
50
+ `max_width` defaults to `80`.
data/README.md ADDED
@@ -0,0 +1,85 @@
1
+ # cowl - column width linter
2
+
3
+ # HOMEPAGE
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
23
+
24
+ ```
25
+ $ cowl examples/
26
+ examples/hello.bf:3:++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.
27
+
28
+ $ wc -L examples/hello.bf
29
+ 106 examples/hello.bf
30
+
31
+ $ cowl -w 106 examples/
32
+ $
33
+
34
+ $ cowl -i .bf examples/
35
+ $
36
+ ```
37
+
38
+ # REQUIREMENTS
39
+
40
+ * [Ruby](https://www.ruby-lang.org/) 2+
41
+ * [grep](http://www.gnu.org/software/grep/) (often built-in, or provided by [git](http://git-scm.com/))
42
+
43
+ E.g., Windows users can `chocolatey install git`.
44
+
45
+ ## Optional
46
+
47
+ * [wc](http://linux.die.net/man/1/wc) can help determine the longest line in a file
48
+
49
+ # INSTALL
50
+
51
+ Install via [RubyGems](http://rubygems.org/):
52
+
53
+ ```
54
+ $ gem install cowl
55
+ ```
56
+
57
+ # CONFIGURE
58
+
59
+ See [CONFIGURE.md](https://github.com/mcandre/cowl/blob/master/CONFIGURE.md) for details.
60
+
61
+ # LICENSE
62
+
63
+ FreeBSD
64
+
65
+ # DEVELOPMENT
66
+
67
+ ## Testing
68
+
69
+ Keep the interface working:
70
+
71
+ ```
72
+ $ cucumber
73
+ ```
74
+
75
+ ## Linting
76
+
77
+ Keep the code tidy:
78
+
79
+ ```
80
+ $ rake lint
81
+ ```
82
+
83
+ ## Git Hooks
84
+
85
+ See `hooks/`.
data/bin/cowl CHANGED
@@ -1,32 +1,30 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ require 'rubygems'
3
4
  require 'find'
4
5
  require 'optparse'
5
-
6
- require 'rubygems'
6
+ require 'yaml'
7
7
  require 'cowl'
8
8
 
9
+ IGNORE_FILENAME = '.cowlignore'
10
+ CONFIGURATION_FILENAME = '.cowlrc.yml'
11
+
9
12
  def main
10
13
  ignores = DEFAULT_IGNORES
11
14
 
12
15
  filenames = ['.']
13
16
 
14
- max_width = DEFAULT_MAX_WIDTH
17
+ configuration_flags = {}
15
18
 
16
19
  option = OptionParser.new do |option|
17
- option.banner = 'Usage: cowl [options] [<files>]'
20
+ option.banner = "Usage: cowl [options] [<files>]"
18
21
 
19
22
  option.on('-i', '--ignore pattern', 'Ignore file names matching Ruby regex pattern') do |pattern|
20
23
  ignores << pattern
21
24
  end
22
25
 
23
- option.on('-w=', '--max-width', 'Maximum column width (default: 80 characters). Must be non-negative.') do |width|
24
- max_width = width.to_i
25
-
26
- if max_width <= 0 then
27
- puts option
28
- exit
29
- end
26
+ 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
30
28
  end
31
29
 
32
30
  option.on('-h', '--help', 'Print usage info') do
@@ -54,16 +52,57 @@ def main
54
52
  end
55
53
  end
56
54
 
57
- recursive_filenames.each { |f| check(f, max_width) }
55
+ configuration_dotfile = DEFAULT_CONFIGURATION
56
+
57
+ recursive_filenames.each do |f|
58
+ dir = File.expand_path("..", f)
59
+
60
+ parent_of_home = File.expand_path("..", ENV["HOME"])
61
+
62
+ while dir != parent_of_home
63
+ ignore_file = dir + File::SEPARATOR + IGNORE_FILENAME
64
+
65
+ if File.exist?(ignore_file) then
66
+ ignores.concat(open(ignore_file).read.split("\n"))
67
+ end
68
+
69
+ dir = File.expand_path("..", dir)
70
+ end
71
+
72
+ if ignores.none? { |ignore| f =~ %r(#{ignore}) } then
73
+ dir = File.expand_path("..", f)
74
+
75
+ parent_of_home = File.expand_path("..", ENV["HOME"])
76
+
77
+ while dir != parent_of_home
78
+ config_file = dir + File::SEPARATOR + CONFIGURATION_FILENAME
79
+
80
+ if File.exist?(config_file) then
81
+ configuration_dotfile = YAML.load_file(config_file)
82
+ break
83
+ else
84
+ dir = File.expand_path("..", dir)
85
+ end
86
+ end
87
+
88
+ # Command line flags override dotfile settings
89
+ configuration = configuration_dotfile.merge(configuration_flags)
90
+
91
+ check(f, configuration)
92
+ end
93
+ end
58
94
  end
59
95
 
60
96
  begin
61
97
  main
62
- # User may quit enlint before completion.
98
+ # User may quit before completion.
63
99
  rescue Interrupt
64
100
  nil
65
- # enlint may be piped to another program (e.g. `less`),
66
- # which is quit before enlint completes.
101
+ # Bad regex
102
+ rescue RegexpError => e
103
+ puts e
104
+ # This program may be piped to another program (e.g. `less`),
105
+ # which is quit before this program completes.
67
106
  rescue Errno::EPIPE, Errno::EMFILE
68
107
  nil
69
108
  end
data/lib/cowl.rb CHANGED
@@ -3,8 +3,6 @@ require 'ptools'
3
3
 
4
4
  require 'version'
5
5
 
6
- DEFAULT_MAX_WIDTH = 80
7
-
8
6
  DEFAULT_IGNORES = %w(
9
7
  .hg/
10
8
  .svn/
@@ -24,6 +22,14 @@ DEFAULT_IGNORES = %w(
24
22
  -min.js
25
23
  )
26
24
 
25
+ DEFAULT_MAX_WIDTH = 80
26
+
27
+ UNLIMITED = 'unlimited'
28
+
29
+ DEFAULT_CONFIGURATION = {
30
+ "max_width" => DEFAULT_MAX_WIDTH
31
+ }
32
+
27
33
  #
28
34
  # Parse, model, and print a line too wide for its own good
29
35
  #
@@ -53,17 +59,26 @@ end
53
59
  def self.recursive_list(directory, ignores = DEFAULT_IGNORES)
54
60
  Find.find(directory).reject do |f|
55
61
  File.directory?(f) ||
56
- ignores.any? { |ignore| f =~ /#{ignore}/ } ||
57
- File.binary?(f)
62
+ ignores.any? { |ignore| f =~ %r(#{ignore}) } ||
63
+
64
+ begin
65
+ File.binary?(f)
66
+ rescue Errno::ENOENT
67
+ true
68
+ end
58
69
  end
59
70
  end
60
71
 
61
- def self.check(filename, width = DEFAULT_MAX_WIDTH)
62
- output = `grep -n \'^.\\{#{width + 1},\\}$\' \"#{filename}\"`
72
+ def self.check(filename, configuration = DEFAULT_CONFIGURATION)
73
+ max_width = configuration["max_width"]
63
74
 
64
- lines = output.split("\n")
75
+ if max_width != UNLIMITED
76
+ output = `grep -n \'^.\\{#{max_width.to_i + 1},\\}$\' \"#{filename}\"`
65
77
 
66
- widenings = lines.map { |line| Widening.parse(filename, line) }
78
+ lines = output.split("\n")
67
79
 
68
- widenings.each { |m| puts m }
80
+ widenings = lines.map { |line| Widening.parse(filename, line) }
81
+
82
+ widenings.each { |m| puts m }
83
+ end
69
84
  end
data/lib/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
  # Cowl
3
3
  #
4
4
  module Cowl
5
- VERSION = '0.1'
5
+ VERSION = '0.2'
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.1'
4
+ version: '0.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Pennebaker
@@ -227,10 +227,12 @@ executables:
227
227
  extensions: []
228
228
  extra_rdoc_files: []
229
229
  files:
230
- - LICENSE.md
231
- - bin/cowl
232
230
  - lib/cowl.rb
233
231
  - lib/version.rb
232
+ - CONFIGURE.md
233
+ - LICENSE.md
234
+ - README.md
235
+ - bin/cowl
234
236
  homepage: https://github.com/mcandre/cowl
235
237
  licenses:
236
238
  - FreeBSD
@@ -251,8 +253,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
251
253
  version: '0'
252
254
  requirements: []
253
255
  rubyforge_project:
254
- rubygems_version: 2.2.2
256
+ rubygems_version: 2.1.10
255
257
  signing_key:
256
258
  specification_version: 4
257
259
  summary: column width linter
258
260
  test_files: []
261
+ has_rdoc: