mdspell 0.1.8 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: df6194fb7f2090573a5c8c393c953f91b7c804d6
4
- data.tar.gz: e93822857823d5c93b52264ed30b03d44c94be9f
3
+ metadata.gz: 9486da2132f09b67ecc6d79b83a5701c5838dae7
4
+ data.tar.gz: 464a9061d93316b14d71e59dc4486193ef58dba5
5
5
  SHA512:
6
- metadata.gz: cc3bfbf1598db0154ccfc6929db8fe790e5f76ea3df7f618c8a3a657f66bf6146d277eea6ed9a63b98ead8814ca3b4c2df305c30bea6de8676010deaef59a98b
7
- data.tar.gz: ab414bf1101f325c63884c1f887027bdf86df3eea897360e730cc55419a942357fa7f91e3178e63d54760b8ad13a0cb6f8afdae09a92b7e2b66e50baebefc92f
6
+ metadata.gz: a8decde7a93905b67e6851aeca803ec8c5435c990d78c961318891bd23603b8ee612f175867971e32c93917f01b9788236fe6cb7e6979aee15ec98f175913940
7
+ data.tar.gz: 319d66b9266d9c460b5d814a405f3f027b36a7bfd213786904cb8dddff87da8b9b4c30859d02c41c687120f1e309b3a738fc0cf022c80792e609b2fe4499cf3b
data/README.md CHANGED
@@ -51,6 +51,27 @@ spec/examples/with_errors.md:5: tobe
51
51
  spec/examples/complete.md:24: Unordered
52
52
  ```
53
53
 
54
+ ### Ignore lists
55
+
56
+ In some cases, there may be words that are legitimately not in the dictionary you are using because they are proper nouns, or obscure technical terms.
57
+
58
+ You may specify words (or even regular expressions) to ignore via the --ignored flag:
59
+
60
+ ```
61
+ mdspell README.md --ignored config,mdspell,ruby.*,file.ame
62
+ ```
63
+
64
+ Likewise, you may specify this in a config file
65
+
66
+ ```
67
+ ignored:
68
+ - expr1
69
+ - word2
70
+ ...
71
+ ```
72
+
73
+ Please note that you should take care to use non-greedy, precise, regular expressions as to not mask legitimate spelling errors.
74
+
54
75
  ## MIT Licensed
55
76
 
56
77
  See [LICENSE](https://github.com/mtuchowski/mdspell/blob/master/LICENSE) file for full license
@@ -17,6 +17,12 @@ module MdSpell
17
17
  long: '--language LANG',
18
18
  description: 'Set documents language'
19
19
 
20
+ option :ignored,
21
+ short: '-i IGNORED1,IGNORED2,...',
22
+ long: '--ignored IGNORED1,IGNORED2,...',
23
+ description: 'CSV of expressions to be ignored',
24
+ proc: proc { |csv| csv.split(',') }
25
+
20
26
  option :verbose,
21
27
  short: '-v',
22
28
  long: '--[no-]verbose',
@@ -35,8 +41,10 @@ module MdSpell
35
41
  def run(options)
36
42
  raise ArgumentError, 'expected Array of command line options' unless options.is_a? Array
37
43
 
38
- parse_options(options)
44
+ # Start clean
45
+ MdSpell::Configuration.reset
39
46
 
47
+ parse_options(options)
40
48
  # Load optional config file if it's present.
41
49
  if config[:config_file]
42
50
  config_filename = File.expand_path(config[:config_file])
@@ -9,6 +9,7 @@ module MdSpell
9
9
 
10
10
  default :config_file, '~/.mdspell'
11
11
  default :language, 'en_US'
12
+ default :ignored, []
12
13
  default :verbose, false
13
14
  default :version, VERSION
14
15
  end
@@ -29,10 +29,10 @@ module MdSpell
29
29
  # Returns found spelling errors.
30
30
  def typos
31
31
  results = []
32
-
33
32
  FFI::Aspell::Speller.open(Configuration[:language]) do |speller|
34
33
  TextLine.scan(document).each do |line|
35
34
  line.words.each do |word|
35
+ next if ignored? word
36
36
  unless speller.correct? word
37
37
  results << Typo.new(line, word, speller.suggestions(word))
38
38
  end
@@ -42,5 +42,24 @@ module MdSpell
42
42
 
43
43
  results
44
44
  end
45
+
46
+ private
47
+
48
+ def ignored?(word)
49
+ # For each ignored word / expression, join them together with
50
+ # An atomic grouping:
51
+ # http://ruby-doc.org/core-2.1.1/Regexp.html#class-Regexp-label-Atomic+Grouping
52
+ # And an alternation using the '|' character:
53
+ # http://ruby-doc.org/core-2.1.1/Regexp.html#class-Regexp-label-Alternation
54
+ # Compile it the result into a single regular expression,
55
+ # and save it as an instance variable so we don't need to recompile.
56
+ return false if Configuration[:ignored].empty?
57
+ @ignored ||= begin
58
+ Regexp.new(Configuration[:ignored].map do |e|
59
+ "(?>#{e})"
60
+ end.join('|'), Regexp::EXTENDED | Regexp::IGNORECASE)
61
+ end
62
+ @ignored =~ word
63
+ end
45
64
  end
46
65
  end
@@ -1,4 +1,4 @@
1
1
  module MdSpell
2
2
  # Current version
3
- VERSION = '0.1.8'.freeze
3
+ VERSION = '0.2.0'.freeze
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mdspell
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marek Tuchowski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-13 00:00:00.000000000 Z
11
+ date: 2016-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kramdown