xolti 0.1.1 → 0.2.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2149450fe72b054a8f677791feaa457def62598e
4
- data.tar.gz: 6c513ac14f888b04fb05a1c0672b292d5c4d4837
3
+ metadata.gz: 2f1e8d541abaefba1d4ecb131cbd52b1c4b2f31c
4
+ data.tar.gz: d7ffe751314f6c5d7ba065ade21037d99e2488e9
5
5
  SHA512:
6
- metadata.gz: ec1776900de5c30d513f1f2d9dc2272a4fad94aaac9de69c9a3fffd0898787049539e86b555c4dbce32b22c5e637f83f23f92ccb798493d5a42516b8812dd5ba
7
- data.tar.gz: 9fe6b19b8f78acd4931f844669052daeb8f0f439b40ffa7ed3b48b6f2b9da50e15e4dfc3183d68ffe2661c243be7cb6af8d6ea61d92b2f0bdb015380ec2a308e
6
+ metadata.gz: 461fdc119faae937058798c78507206bc2d15820032113d0f34fa03011329e365ad86bb23771fa6a3fe00612dab946cd39f8262d8f3d1ecf339b90bcefa154a5
7
+ data.tar.gz: e89ab42c45a166ea8340508b5f193d2dce70beefb57ea84f5f07302880479612ffa10f1353732c873a73f27e6ff39ebaf39f70b709d71c5a37bb9f0369695943
data/.xoltignore CHANGED
@@ -1,6 +1,3 @@
1
1
  *
2
- .*
3
- !lib
4
- !test
5
- !*.rb
6
- !exe
2
+ !lib/**/*.rb
3
+ !test/**/*.rb
data/LICENSE CHANGED
@@ -641,7 +641,7 @@ the Free Software Foundation, either version 3 of the License, or
641
641
 
642
642
  This program is distributed in the hope that it will be useful,
643
643
  but WITHOUT ANY WARRANTY; without even the implied warranty of
644
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
644
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645
645
  GNU General Public License for more details.
646
646
 
647
647
  You should have received a copy of the GNU General Public License
@@ -74,13 +74,7 @@ would be :
74
74
 
75
75
  .. tip::
76
76
 
77
- You can invert a rule by prefixing it with ``!``. You can create one ``.xoltignore``
78
- in each directory of your project. Globing (ie use of the ``*`` wildcard) is supported.
79
-
80
- .. note::
81
-
82
- Like in a ``.gitignore`` file, rules are read line by line, from top to bottom; lower rules
83
- override higher ones, and rules from a deeper folder override rules from higher folders.
77
+ More details on ``.xoltignore`` files can be found :doc:`in the dedicated documentation page </xoltignore>`
84
78
 
85
79
  Checking which files are missing headers
86
80
  ----------------------------------------
@@ -94,7 +88,7 @@ We can either use the dedicated command:
94
88
  Files missing (proper) header:
95
89
  app.js
96
90
 
97
- ... or use ``xolti status``, which will tell you the state of each of your files.
91
+ ... or use ``xolti status``, which will report the files without correct headers.
98
92
 
99
93
  .. code-block:: bash
100
94
 
@@ -105,7 +99,7 @@ We can either use the dedicated command:
105
99
  Adding the header to your files
106
100
  -------------------------------
107
101
 
108
- Looks like ``app.js`` is missing a header. Xolti can create and insert one for you, with the
102
+ Looks like ``app.js`` is missing a header... Xolti can create and insert one for you, with the
109
103
  ``add`` command:
110
104
 
111
105
  .. code-block:: bash
@@ -127,11 +121,11 @@ Verifying the result
127
121
  --------------------
128
122
 
129
123
  Of course, you can verify that Xolti have actually added the header by simply opening the
130
- file, but you can also use the ``check`` command:
124
+ file, but you can also use once again the ``status`` command:
131
125
 
132
126
  .. code-block:: bash
133
127
 
134
- remi ~/myAwesomeProject]$ xolti check app.js
128
+ remi ~/myAwesomeProject]$ xolti status app.js
135
129
  Correct header.
136
130
 
137
131
  That's it ! Your project is correctly licensed :).
@@ -143,17 +137,17 @@ Now that we think of it, ``myAwesomeProject`` is not such a good name. ``myFanta
143
137
  is way better ! To let xolti know of our change of mind, we can edit the ``xolti.yml`` file,
144
138
  and replace the value of the key ``project_name`` by ``myFantasticProject``.
145
139
 
146
- If we ``check`` again the ``app.js`` file, xolti warns us about its now incorrect header:
140
+ When we ask xolti once again about the status of the ``app.js`` file, it warns us about the now incorrect header:
147
141
 
148
142
  .. code-block:: bash
149
143
 
150
- xolti check app.js
144
+ remi ~/myAwesomeProject]$ xolti status app.js
151
145
  Line 5: expected "myFantasticProject" but got "myAwesomeProject".
152
146
  Line 7: expected "myFantasticProject" but got "myAwesomeProject".
153
147
  Line 12: expected "myFantasticProject" but got "myAwesomeProject".
154
148
  Line 18: expected "myFantasticProject" but got "myAwesomeProject".
155
149
 
156
- You can then correct this outdated header.
150
+ You can then manually correct this outdated header.
157
151
 
158
152
  Deleting the header in a file
159
153
  -----------------------------
data/docs/index.rst CHANGED
@@ -9,3 +9,4 @@ Contents:
9
9
  intro
10
10
  installation
11
11
  getting_started
12
+ xoltignore
@@ -1,7 +1,7 @@
1
1
  Installation
2
2
  ============
3
3
 
4
- Xolti being available on `RubyGems.org`_ makes it fairly easy to be installed :
4
+ Xolti is available on `RubyGems.org`, the Ruby community's gem hosting service. Assuming you have already installed Ruby, this makes Xolti fairly easy to install :
5
5
 
6
6
  .. code-block:: bash
7
7
 
@@ -0,0 +1,65 @@
1
+ Xoltignore reference
2
+ ====================
3
+
4
+ In the same fashion git uses ``.gitignore`` files to know which files to track or not, xolti uses ``.xoltignore`` files to detect which files needs a header or not.
5
+
6
+ You can create one ``.xoltignore`` in each directory of your project.
7
+
8
+ Syntax
9
+ ------
10
+
11
+ ``.xoltignore`` files are plain text files, using a sub-set of the syntax of ``.gitignore`` :
12
+
13
+ - Each line specifies a pattern used to ignore or not a path
14
+ - A line is ignored if it is blank or starts with ``#```
15
+ - Globing (use of ``*`` and/or ``**`` wildcards) is supported
16
+ - A pattern can be inverted by prefixing it with ``!``
17
+ - Pattern are read line by line, from top to bottom; lower rules override higher ones, and rules from a deeper folder override rules from higher folders
18
+ - A pattern ending with ``/`` matches only directories
19
+
20
+ Example : js project
21
+ --------------------
22
+
23
+ Folders/files structure :
24
+
25
+ .. code-block:: text
26
+
27
+ |- Javascript_Project
28
+ |- app.js
29
+ |- package.json
30
+ |- node_modules
31
+ |- ...
32
+
33
+ Possible ``.xoltignore`` :
34
+
35
+ .. code-block:: text
36
+
37
+ # Ignore files installed by npm
38
+ node_modules
39
+
40
+ # Ignore package.json
41
+ package.json
42
+
43
+ Example : java maven project
44
+ ----------------------------
45
+
46
+ Folders/files structure :
47
+
48
+ .. code-block:: text
49
+
50
+ |- Java_Maven_Project
51
+ |- pom.xml
52
+ |- readme
53
+ |- src
54
+ |- main
55
+ |- java
56
+ |- App.java
57
+
58
+ Possible ``.xoltignore`` :
59
+
60
+ .. code-block:: text
61
+
62
+ # Ignore all files but pom.xml and java sources
63
+ *
64
+ !pom.xml
65
+ !src/**/*.java
data/exe/xolti CHANGED
@@ -12,7 +12,7 @@
12
12
  #
13
13
  # Xolti is distributed in the hope that it will be useful,
14
14
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
16
  # GNU General Public License for more details.
17
17
  #
18
18
  # You should have received a copy of the GNU General Public License
data/lib/comment.rb CHANGED
@@ -10,7 +10,7 @@
10
10
  #
11
11
  # Xolti is distributed in the hope that it will be useful,
12
12
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
14
  # GNU General Public License for more details.
15
15
  #
16
16
  # You should have received a copy of the GNU General Public License
data/lib/config.rb CHANGED
@@ -10,7 +10,7 @@
10
10
  #
11
11
  # Xolti is distributed in the hope that it will be useful,
12
12
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
14
  # GNU General Public License for more details.
15
15
  #
16
16
  # You should have received a copy of the GNU General Public License
@@ -42,7 +42,7 @@ class XoltiConfig
42
42
  @project_info = extract_project_info(raw_config["project_info"])
43
43
  @comment = DefaultComment::HASH.merge!(raw_config["comment"] || {})
44
44
  @license = raw_config["license"]
45
- @template = raw_config.include?("template") ? raw_config["template"] : IO.binread(Resources.get_template_path(@license))
45
+ @template = extract_template_if_present(raw_config)
46
46
  @offset = raw_config["offset"] || 0
47
47
  end
48
48
 
@@ -57,4 +57,11 @@ class XoltiConfig
57
57
  year: raw_project_info["year"] || Date.today().year.to_s
58
58
  }
59
59
  end
60
+
61
+ private def extract_template_if_present(raw_config)
62
+ return raw_config["template"] if raw_config.include?("template")
63
+ default_template_path = Resources.get_template_path(@license)
64
+ return IO.binread(default_template_path) if File.exists?(default_template_path)
65
+ nil
66
+ end
60
67
  end
data/lib/core.rb CHANGED
@@ -10,7 +10,7 @@
10
10
  #
11
11
  # Xolti is distributed in the hope that it will be useful,
12
12
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
14
  # GNU General Public License for more details.
15
15
  #
16
16
  # You should have received a copy of the GNU General Public License
@@ -45,7 +45,7 @@ module Core
45
45
  template = config.template
46
46
  ext = File.extname(path)
47
47
  detected = HeaderDetector.detect(path, template, config.get_comment(ext))
48
- return [{type: "no_header_found"}] if !detected
48
+ return [{type: :no_header_found}] if !detected
49
49
  HeaderValidator.diff(detected, config.project_info.merge({file_name: File.basename(path)}))
50
50
  end
51
51
  end
@@ -1,5 +1,5 @@
1
1
  # default_comment_tokens.rb
2
- # Copyright (C) Rémi Even 2016
2
+ # Copyright (C) Rémi Even 2016-2017
3
3
  #
4
4
  # This file is part of Xolti.
5
5
  #
@@ -10,7 +10,7 @@
10
10
  #
11
11
  # Xolti is distributed in the hope that it will be useful,
12
12
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
14
  # GNU General Public License for more details.
15
15
  #
16
16
  # You should have received a copy of the GNU General Public License
@@ -33,6 +33,7 @@ class DefaultComment
33
33
  "e" => ["--", "-- ", "--"],
34
34
  "el" => ["!!!", "!!! ", "!!!"],
35
35
  "erl" => ["%%%", "%%% ", "%%%"],
36
+ "elm" => ["{-", " ", "-}"],
36
37
  "f" => ["!", "! ", "!"],
37
38
  "fml" => ["<!--", " ", "-->"],
38
39
  "ftl" => ["<#--", " ", "-->"],
data/lib/file_finder.rb CHANGED
@@ -10,46 +10,46 @@
10
10
  #
11
11
  # Xolti is distributed in the hope that it will be useful,
12
12
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
14
  # GNU General Public License for more details.
15
15
  #
16
16
  # You should have received a copy of the GNU General Public License
17
17
  # along with Xolti. If not, see <http://www.gnu.org/licenses/>.
18
- # TODO : handle "folder/file" patterns
18
+
19
+ require_relative "path_rule"
20
+
19
21
  def parse_xoltignore(path)
20
- xoltignorePath = "#{path}/.xoltignore"
21
- return [] if !File.file?(xoltignorePath)
22
- File.readlines(xoltignorePath).reject {|line| line == "" || line[0] == "#"}.map {|line| line.chomp}
22
+ xoltignore_path = "#{path}/.xoltignore"
23
+ return [] if !File.file?(xoltignore_path)
24
+ File.readlines(xoltignore_path)
25
+ .reject {|line| line == "" || line[0] == "#"}
26
+ .map {|line| line.chomp}
27
+ .map {|line| PathRule.new(path, line)}
23
28
  end
24
29
 
25
30
  module FileFinder
26
- def FileFinder.explore_folder(folder=Dir.pwd, ignoreRules=[])
27
- fileAcc = []
28
- ignoredPaths = [".", "..", ".git", ".xoltignore", "xolti.yml", "LICENSE"]
29
- ignoreRules += parse_xoltignore(folder)
31
+ def FileFinder.explore_folder(folder=Dir.pwd, ignore_rules=[])
32
+ files = []
33
+ ignored_paths = [".", "..", ".git", ".xoltignore", "xolti.yml", "LICENSE"]
34
+ ignore_rules += parse_xoltignore(folder)
30
35
 
31
36
  Dir.glob("#{folder}/{*,.*}")
32
- .delete_if {|x| ignoredPaths.include?(File.basename(x))}
33
- .delete_if do |x|
34
- basename = File.basename(x)
35
- toIgnore = false
36
- ignoreRules.each do |rule|
37
- if (rule[0] == "!" && File.fnmatch(rule[1..-1], basename))
38
- toIgnore = false
39
- elsif (File.fnmatch(rule, basename))
40
- toIgnore = true
41
- end
42
- end
43
- toIgnore
44
- end
37
+ .delete_if {|x| ignored_paths.include?(File.basename(x))}
45
38
  .each do |path|
39
+ # Do NOT ignore by default
40
+ ignore = :exclude
46
41
  if File.directory?(path)
47
- fileAcc += explore_folder(path, ignoreRules)
42
+ ignore_rules.each do |rule|
43
+ ignore = rule.effect if rule.folder_match(path)
44
+ end
45
+ files += explore_folder(path, ignore_rules) if ignore == :exclude
48
46
  else
49
- fileAcc << path
47
+ ignore_rules.each do |rule|
48
+ ignore = rule.effect if rule.file_match(path)
49
+ end
50
+ files << path if ignore == :exclude
50
51
  end
51
52
  end
52
-
53
- fileAcc
53
+ files
54
54
  end
55
55
  end
@@ -10,7 +10,7 @@
10
10
  #
11
11
  # Xolti is distributed in the hope that it will be useful,
12
12
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
14
  # GNU General Public License for more details.
15
15
  #
16
16
  # You should have received a copy of the GNU General Public License
@@ -10,7 +10,7 @@
10
10
  #
11
11
  # Xolti is distributed in the hope that it will be useful,
12
12
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
14
  # GNU General Public License for more details.
15
15
  #
16
16
  # You should have received a copy of the GNU General Public License
@@ -10,21 +10,17 @@
10
10
  #
11
11
  # Xolti is distributed in the hope that it will be useful,
12
12
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
14
  # GNU General Public License for more details.
15
15
  #
16
16
  # You should have received a copy of the GNU General Public License
17
17
  # along with Xolti. If not, see <http://www.gnu.org/licenses/>.
18
18
  require_relative "comment"
19
19
 
20
- def complete_template(path, info, template)
21
- template %= info.merge({file_name: File.basename(path)})
22
- template
23
- end
24
-
25
20
  module HeaderGenerator
26
21
  def HeaderGenerator.create_for(path, config)
27
- bare_header = complete_template(path, config.project_info, config.template)
22
+ info = config.project_info.merge({file_name: File.basename(path)})
23
+ bare_header = config.template % info
28
24
  Comment.comment(bare_header, config.get_comment(File.extname(path)))
29
25
  end
30
26
  end
@@ -10,7 +10,7 @@
10
10
  #
11
11
  # Xolti is distributed in the hope that it will be useful,
12
12
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
14
  # GNU General Public License for more details.
15
15
  #
16
16
  # You should have received a copy of the GNU General Public License
data/lib/path_rule.rb ADDED
@@ -0,0 +1,70 @@
1
+ # path_rule.rb
2
+ # Copyright (C) Rémi Even 2017
3
+ #
4
+ # This file is part of Xolti.
5
+ #
6
+ # Xolti is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # Xolti is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with Xolti. If not, see <http://www.gnu.org/licenses/>.
18
+ class PathRule
19
+
20
+ attr_reader :effect
21
+
22
+ def initialize(path, pattern)
23
+ if pattern.start_with?("!") then
24
+ @effect = :exclude
25
+ pattern = pattern[1..-1]
26
+ else
27
+ @effect = :include
28
+ end
29
+ @file_regexp = pattern_to_file_regexp(path, pattern)
30
+ @folder_regexp = pattern_to_folder_regexp(path, pattern)
31
+ end
32
+
33
+ def file_match(path)
34
+ @file_regexp =~ path
35
+ end
36
+
37
+ def folder_match(path)
38
+ @folder_regexp =~ path
39
+ end
40
+
41
+ private def pattern_to_file_regexp(path, pattern)
42
+ return nil if concern_only_folders(pattern)
43
+ Regexp.new(glob_to_regexp(pattern).unshift(Regexp.escape(path)).join())
44
+ end
45
+
46
+ private def pattern_to_folder_regexp(path, pattern)
47
+ pattern = pattern.chomp("/")
48
+ prefix_detector_regexp = glob_to_regexp(pattern)
49
+ .reverse()
50
+ .reduce do |acc, s|
51
+ "#{s}(#{acc})?"
52
+ end
53
+ Regexp.new(path + prefix_detector_regexp)
54
+ end
55
+
56
+ private def concern_only_folders(pattern)
57
+ pattern.end_with?("/") || pattern.end_with?("**")
58
+ end
59
+
60
+ private def glob_to_regexp(pattern)
61
+ pattern.split("/")
62
+ .map do |e|
63
+ if e == "**" then
64
+ "(/.*)?"
65
+ else
66
+ Regexp.escape("/" + e).gsub("\\*", "[^/]*")
67
+ end
68
+ end
69
+ end
70
+ end