lili 0.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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/bin/lili +49 -3
  3. data/lib/lili.rb +32 -13
  4. data/lib/version.rb +1 -1
  5. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 68335b3856e8891e5ba3d9729ea8e92eed2128ac
4
- data.tar.gz: f34b4e49f42c14e80e5e9602755ab2faaed50119
3
+ metadata.gz: 825e18c500816a2d445dfb055260438524253108
4
+ data.tar.gz: eea5d057b10768685ba6029968faf06e3157c820
5
5
  SHA512:
6
- metadata.gz: ac0b6b22e3047b29c913d4b4abcf7bf8496d63d6433bf23cbc2c9ca7670fa100bbd4a2a7b8afdf4c39b7ac80d812a8daddf506857b41e5a962b28b9ffaf7bc03
7
- data.tar.gz: d90796255691835e45d4f60d2305667e7bbc69af1a0bfa6d5e5ebbd7c94dd4f3c86cfac8c66792c29d3dbdbd71054a45baef12778aee4c2ca52863d57de320e3
6
+ metadata.gz: 51596df41d135cc6c70f8cc9312675be5ee490f3b97bb17c7e40e061726dfe9aacf033ba4e320f78217de834c84c89f4d6438047c2049c3f4461ce6452172925
7
+ data.tar.gz: 22cccb6757d4d6ba3d13b1f0c75420f3c91d546964ee90f5e21b1385877a988dd4149209ff8a26dbeb194f91b8d837d859a722b49ad6f4f9dd082dae73019bdc
data/bin/lili CHANGED
@@ -1,16 +1,21 @@
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 'lili'
8
8
 
9
+ IGNORE_FILENAME = '.lili-ignore'
10
+ CONFIGURATION_FILENAME = '.lili-rc.yml'
11
+
9
12
  def main
10
13
  ignores = DEFAULT_IGNORES
11
14
 
12
15
  filenames = ['.']
13
16
 
17
+ configuration_flags = {}
18
+
14
19
  option = OptionParser.new do |option|
15
20
  option.banner = 'Usage: lili [options] [<files>]'
16
21
 
@@ -43,7 +48,48 @@ def main
43
48
  end
44
49
  end
45
50
 
46
- recursive_filenames.each { |f| check f }
51
+ configuration_dotfile = DEFAULT_CONFIGURATION
52
+
53
+ recursive_filenames.each do |f|
54
+ dir = File.expand_path("..", f)
55
+
56
+ parent_of_home = File.expand_path("..", ENV["HOME"])
57
+
58
+ while dir != parent_of_home
59
+ ignore_file = dir + File::SEPARATOR + IGNORE_FILENAME
60
+
61
+ if File.exist?(ignore_file) then
62
+ ignores.concat(open(ignore_file).read.split("\n"))
63
+ end
64
+
65
+ dir = File.expand_path("..", dir)
66
+ end
67
+
68
+ if ignores.none? { |ignore| f =~ %r(#{ignore}) } then
69
+ dir = File.expand_path("..", f)
70
+
71
+ parent_of_home = File.expand_path("..", ENV["HOME"])
72
+
73
+ while dir != parent_of_home
74
+ config_file = dir + File::SEPARATOR + CONFIGURATION_FILENAME
75
+
76
+ if File.exist?(config_file) then
77
+ configuration_dotfile = DEFAULT_CONFIGURATION.merge(YAML.load_file(config_file))
78
+ break
79
+ else
80
+ dir = File.expand_path("..", dir)
81
+ end
82
+ end
83
+
84
+ # Hack to Reset configuration when changing directories
85
+ configuration_dotfile = DEFAULT_CONFIGURATION unless File.exist?(dir + File::SEPARATOR + CONFIGURATION_FILENAME)
86
+
87
+ # Command line flags override dotfile settings
88
+ configuration = configuration_dotfile.merge(configuration_flags)
89
+
90
+ check(f, configuration)
91
+ end
92
+ end
47
93
  end
48
94
 
49
95
  begin
@@ -8,7 +8,6 @@ DEFAULT_IGNORES = %w(
8
8
  \.hg/
9
9
  \.svn/
10
10
  \.git/
11
- \.git
12
11
  \.gitignore
13
12
  node_modules/
14
13
  \.vagrant/
@@ -28,12 +27,17 @@ DEFAULT_IGNORES = %w(
28
27
  # Only the earliest file pattern match's rule applies.
29
28
  #
30
29
  DEFAULT_RULES = [
31
- [/[\.-]min\./, /^none$/],
32
- [/\.reg$/, /^crlf$/],
33
- [/\.bat$/, /^crlf$/],
34
- [/.*/, /^lf$/]
30
+ [/[\.-]min\./, [/^none$/, /^false$/]],
31
+ [/\.reg$/, [/^crlf|none$/, /^false$/]],
32
+ [/\.bat$/, [/^crlf|none$/, /^false$/]],
33
+ [/\.ps1$/, [/^crlf|none$/, /^false$/]],
34
+ [/.*/, [/^lf|none$/, /^true$/]]
35
35
  ]
36
36
 
37
+ DEFAULT_CONFIGURATION = {
38
+ 'rules' => DEFAULT_RULES
39
+ }
40
+
37
41
  # Warning for files that do not exist
38
42
  NO_SUCH_FILE = 'does not exist'
39
43
 
@@ -42,22 +46,35 @@ NO_SUCH_FILE = 'does not exist'
42
46
  # Distinct from Ruby's built-in Encoding class.
43
47
  #
44
48
  class ALineEnding
45
- attr_accessor :filename, :line_ending
49
+ attr_accessor :filename, :line_ending, :final_eol
46
50
 
47
- def self.parse(filename, line_ending)
48
- ALineEnding.new(filename, line_ending.to_s)
51
+ def self.parse(filename, report)
52
+ ALineEnding.new(filename, report.line_ending.to_s, report.final_eol.to_s)
49
53
  end
50
54
 
51
- def initialize(filename, line_ending)
55
+ def initialize(filename, line_ending, final_eol)
52
56
  @filename = filename
53
57
  @line_ending = line_ending
58
+ @final_eol = final_eol
54
59
  end
55
60
 
56
61
  def violate?(rules)
57
62
  preferred = rules.select { |rule| filename =~ rule.first }.first[1]
58
63
 
59
- if ! (line_ending =~ preferred)
60
- [line_ending, preferred]
64
+ preferred_line_ending = preferred[0]
65
+ preferred_final_eol = preferred[1]
66
+
67
+ if ! (@line_ending =~ preferred_line_ending)
68
+ [@line_ending, preferred_line_ending]
69
+ elsif ! (@final_eol =~ preferred_final_eol)
70
+ [
71
+ if !final_eol
72
+ 'with final eol'
73
+ else
74
+ 'without final eol'
75
+ end,
76
+ preferred_final_eol
77
+ ]
61
78
  else
62
79
  false
63
80
  end
@@ -87,11 +104,13 @@ def self.recursive_list(directory, ignores = DEFAULT_IGNORES)
87
104
  end
88
105
  end
89
106
 
90
- def self.check(filename, rules = DEFAULT_RULES)
107
+ def self.check(filename, configuration = DEFAULT_CONFIGURATION)
108
+ rules = configuration['rules']
109
+
91
110
  if !File.zero?(filename)
92
111
  line_ending = ALineEnding.parse(
93
112
  filename,
94
- LineDetector.detect_line_ending_of_file(filename)
113
+ LineDetector.report_of_file(filename)
95
114
  )
96
115
 
97
116
  line_ending_difference = line_ending.violate?(rules)
@@ -2,5 +2,5 @@
2
2
  # LiLi
3
3
  #
4
4
  module LiLi
5
- VERSION = '0.0'
5
+ VERSION = '0.1'
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lili
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.0'
4
+ version: '0.1'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Pennebaker
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - ~>
32
32
  - !ruby/object:Gem::Version
33
- version: '0.2'
33
+ version: '0.3'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ~>
39
39
  - !ruby/object:Gem::Version
40
- version: '0.2'
40
+ version: '0.3'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement