mdspell 0.1.0 → 0.1.1

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: 557ab534f964bbd18e0453ddcbe9561698441d5b
4
- data.tar.gz: bb03a5b7f5a40b1e1fe689d383abd1a35a4ccaa8
3
+ metadata.gz: 167c31fb49e320ecb9a67cae141e171b806446ea
4
+ data.tar.gz: 209aa4bc10977836b2ab9458510fb798a3621d2b
5
5
  SHA512:
6
- metadata.gz: 21066ee2957e17175a5c353dacd2d9aea1a0a7067ef83813fad211c4548705027867509cfed1a4195893840013e2e92986b9ab8a34ffe6f22c66c81bc3562299
7
- data.tar.gz: c96d072fc81fb88d458807e34953dcae4c01f96d3ec997f8269e527025ee5f1b6b4f4216ce1a9ffc50875b25efdf26b97478e5510833b888cde9ddf0777ecb1f
6
+ metadata.gz: bd3666dcba329f752f9ce3f5c87ace2cbbbaea87a6613a124fae877823a2558302e905fa8f786eed2f9581e0de6256c18154b94103e1f6ab5da557dfe551b551
7
+ data.tar.gz: 7e5b5582be2cc45272e47586693ce108488e6d2b0bd66c8728cc27a254b75488a7a5310254138df3b04f4f81a909acf9c3e0a971d8d70de3a925897714b886bd
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # MdSpell
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/mdspell.svg)](http://badge.fury.io/rb/mdspell)
3
4
  [![Build Status](https://travis-ci.org/mtuchowski/mdspell.svg)](
4
5
  https://travis-ci.org/mtuchowski/mdspell)
5
6
  [![Code Climate](https://codeclimate.com/github/mtuchowski/mdspell/badges/gpa.svg)](
@@ -1,9 +1,9 @@
1
+ require_relative 'mdspell/version'
1
2
  require_relative 'mdspell/cli'
2
3
  require_relative 'mdspell/configuration'
3
4
  require_relative 'mdspell/spell_checker'
4
5
  require_relative 'mdspell/text_line'
5
6
  require_relative 'mdspell/typo'
6
- require_relative 'mdspell/version'
7
7
 
8
8
  require 'rainbow'
9
9
 
@@ -15,10 +15,12 @@ module MdSpell
15
15
 
16
16
  # Spell-check each file.
17
17
  cli.files.each do |filename|
18
- verbose "Spell-checking #{filename}..."
18
+ spell_checker = SpellChecker.new(filename)
19
+
20
+ verbose "Spell-checking #{spell_checker.filename}..."
19
21
 
20
- SpellChecker.new(filename).typos.each do |typo|
21
- error "#{filename}:#{typo.line.location}: #{typo.word}"
22
+ spell_checker.typos.each do |typo|
23
+ error "#{spell_checker.filename}:#{typo.line.location}: #{typo.word}"
22
24
  end
23
25
  end
24
26
  end
@@ -8,16 +8,14 @@ module MdSpell
8
8
  banner "Usage: #{File.basename($PROGRAM_NAME)} [options] [FILE.md|DIR ...]"
9
9
 
10
10
  option :config_file,
11
- short: '-c',
11
+ short: '-c FILE',
12
12
  long: '--config FILE',
13
- description: 'The configuration file to use',
14
- default: '~/.mdspell'
13
+ description: 'The configuration file to use'
15
14
 
16
15
  option :language,
17
- short: '-l',
16
+ short: '-l LANG',
18
17
  long: '--language LANG',
19
- description: 'Set documents language',
20
- default: 'en_US'
18
+ description: 'Set documents language'
21
19
 
22
20
  option :verbose,
23
21
  short: '-v',
@@ -35,11 +33,15 @@ module MdSpell
35
33
  exit: 0
36
34
 
37
35
  def run(argv = ARGV)
36
+ fail ArgumentError, 'expected Array of command line options' unless argv.is_a? Array
37
+
38
38
  parse_options(argv)
39
39
 
40
40
  # Load optional config file if it's present.
41
- config_filename = File.expand_path(config[:config_file])
42
- MdSpell::Configuration.from_file(config_filename) if File.exist?(config_filename)
41
+ if config[:config_file]
42
+ config_filename = File.expand_path(config[:config_file])
43
+ MdSpell::Configuration.from_file(config_filename) if File.exist?(config_filename)
44
+ end
43
45
 
44
46
  # Store command line configuration options.
45
47
  MdSpell::Configuration.merge!(config)
@@ -53,6 +55,7 @@ module MdSpell
53
55
  end
54
56
  end
55
57
  cli_arguments.flatten!
58
+ cli_arguments
56
59
  end
57
60
  end
58
61
  end
@@ -4,5 +4,12 @@ module MdSpell
4
4
  # Stores configuration from both command line and config file.
5
5
  class Configuration
6
6
  extend Mixlib::Config
7
+
8
+ config_strict_mode true
9
+
10
+ default :config_file, '~/.mdspell'
11
+ default :language, 'en_US'
12
+ default :verbose, false
13
+ default :version, VERSION
7
14
  end
8
15
  end
@@ -15,8 +15,15 @@ module MdSpell
15
15
  # Create a new instance from specified file.
16
16
  # @param filename [String] a name of file to load.
17
17
  def initialize(filename)
18
- @filename = filename
19
- @document = Kramdown::Document.new(File.read(filename), input: 'GFM')
18
+ if filename == '-'
19
+ @filename = 'stdin'
20
+ text = STDIN.read
21
+ else
22
+ @filename = filename
23
+ text = File.read(filename)
24
+ end
25
+
26
+ @document = Kramdown::Document.new(text, input: 'GFM')
20
27
  end
21
28
 
22
29
  # Returns found spelling errors.
@@ -1,3 +1,6 @@
1
+ # rubocop:disable Style/Documentation
2
+
1
3
  module MdSpell
2
- VERSION = '0.1.0'
4
+ # Current version
5
+ VERSION = '0.1.1'
3
6
  end
@@ -1,39 +1,58 @@
1
1
  example_id | status | run_time |
2
2
  --------------------------------------------- | ------- | --------------- |
3
- ./spec/mdspell/spell_checker_spec.rb[1:1:1] | passed | 0.00141 seconds |
4
- ./spec/mdspell/spell_checker_spec.rb[1:1:2] | passed | 0.00088 seconds |
5
- ./spec/mdspell/spell_checker_spec.rb[1:1:3] | passed | 0.00055 seconds |
3
+ ./spec/mdspell/cli_spec.rb[1:1] | passed | 0.0001 seconds |
4
+ ./spec/mdspell/cli_spec.rb[1:2] | passed | 0.00012 seconds |
5
+ ./spec/mdspell/cli_spec.rb[1:3:1] | passed | 0.00016 seconds |
6
+ ./spec/mdspell/cli_spec.rb[1:4:1:1] | passed | 0.00041 seconds |
7
+ ./spec/mdspell/cli_spec.rb[1:4:2:1] | passed | 0.00054 seconds |
8
+ ./spec/mdspell/cli_spec.rb[1:4:3:1] | passed | 0.00111 seconds |
9
+ ./spec/mdspell/configuration_spec.rb[1:1:1] | passed | 0.00033 seconds |
10
+ ./spec/mdspell/configuration_spec.rb[1:1:2:1] | passed | 0.00038 seconds |
11
+ ./spec/mdspell/configuration_spec.rb[1:1:2:2] | passed | 0.00034 seconds |
12
+ ./spec/mdspell/configuration_spec.rb[1:1:3:1] | passed | 0.00055 seconds |
13
+ ./spec/mdspell/configuration_spec.rb[1:2:1] | passed | 0.00034 seconds |
14
+ ./spec/mdspell/configuration_spec.rb[1:2:2:1] | passed | 0.00035 seconds |
15
+ ./spec/mdspell/configuration_spec.rb[1:2:2:2] | passed | 0.00038 seconds |
16
+ ./spec/mdspell/configuration_spec.rb[1:3:1] | passed | 0.00071 seconds |
17
+ ./spec/mdspell/configuration_spec.rb[1:3:2:1] | passed | 0.00037 seconds |
18
+ ./spec/mdspell/configuration_spec.rb[1:3:2:2] | passed | 0.00035 seconds |
19
+ ./spec/mdspell/configuration_spec.rb[1:4:1] | passed | 0.00033 seconds |
20
+ ./spec/mdspell/configuration_spec.rb[1:4:2:1] | passed | 0.00043 seconds |
21
+ ./spec/mdspell/configuration_spec.rb[1:4:2:2] | passed | 0.00044 seconds |
22
+ ./spec/mdspell/spell_checker_spec.rb[1:1:1] | passed | 0.00059 seconds |
23
+ ./spec/mdspell/spell_checker_spec.rb[1:1:2] | passed | 0.0006 seconds |
24
+ ./spec/mdspell/spell_checker_spec.rb[1:1:3] | passed | 0.00066 seconds |
6
25
  ./spec/mdspell/spell_checker_spec.rb[1:2:1] | passed | 0.00014 seconds |
7
- ./spec/mdspell/spell_checker_spec.rb[1:2:2] | passed | 0.00048 seconds |
8
- ./spec/mdspell/spell_checker_spec.rb[1:2:3] | failed | 0.01636 seconds |
9
- ./spec/mdspell/spell_checker_spec.rb[1:3:1] | passed | 0.03322 seconds |
10
- ./spec/mdspell/spell_checker_spec.rb[1:3:2:1] | failed | 0.00015 seconds |
11
- ./spec/mdspell/spell_checker_spec.rb[1:4:1] | passed | 0.00181 seconds |
12
- ./spec/mdspell/spell_checker_spec.rb[1:5:1] | failed | 0.00789 seconds |
13
- ./spec/mdspell/spell_checker_spec.rb[1:5:2] | passed | 0.00703 seconds |
26
+ ./spec/mdspell/spell_checker_spec.rb[1:2:2] | passed | 0.00035 seconds |
27
+ ./spec/mdspell/spell_checker_spec.rb[1:2:3] | passed | 0.0005 seconds |
28
+ ./spec/mdspell/spell_checker_spec.rb[1:3:1] | passed | 0.00116 seconds |
29
+ ./spec/mdspell/spell_checker_spec.rb[1:3:2:1] | passed | 0.00074 seconds |
30
+ ./spec/mdspell/spell_checker_spec.rb[1:4:1] | passed | 0.03383 seconds |
31
+ ./spec/mdspell/spell_checker_spec.rb[1:5:1] | passed | 0.01874 seconds |
32
+ ./spec/mdspell/spell_checker_spec.rb[1:5:2] | passed | 0.00913 seconds |
14
33
  ./spec/mdspell/spell_checker_spec.rb[1:5:3] | pending | 0.00001 seconds |
15
- ./spec/mdspell/text_line_spec.rb[1:1:1] | passed | 0.00007 seconds |
16
- ./spec/mdspell/text_line_spec.rb[1:1:2] | passed | 0.00008 seconds |
17
- ./spec/mdspell/text_line_spec.rb[1:1:3] | passed | 0.00008 seconds |
18
- ./spec/mdspell/text_line_spec.rb[1:1:4] | passed | 0.00009 seconds |
19
- ./spec/mdspell/text_line_spec.rb[1:2:1] | passed | 0.0004 seconds |
20
- ./spec/mdspell/text_line_spec.rb[1:3:1] | passed | 0.00008 seconds |
21
- ./spec/mdspell/text_line_spec.rb[1:4:1] | passed | 0.00009 seconds |
22
- ./spec/mdspell/text_line_spec.rb[1:5:1] | passed | 0.0001 seconds |
23
- ./spec/mdspell/text_line_spec.rb[1:6:1] | passed | 0.00014 seconds |
24
- ./spec/mdspell/text_line_spec.rb[1:6:2:1] | passed | 0.00008 seconds |
34
+ ./spec/mdspell/text_line_spec.rb[1:1:1] | passed | 0.00008 seconds |
35
+ ./spec/mdspell/text_line_spec.rb[1:1:2] | passed | 0.00009 seconds |
36
+ ./spec/mdspell/text_line_spec.rb[1:1:3] | passed | 0.00007 seconds |
37
+ ./spec/mdspell/text_line_spec.rb[1:1:4] | passed | 0.00007 seconds |
38
+ ./spec/mdspell/text_line_spec.rb[1:2:1] | passed | 0.00013 seconds |
39
+ ./spec/mdspell/text_line_spec.rb[1:3:1] | passed | 0.00007 seconds |
40
+ ./spec/mdspell/text_line_spec.rb[1:4:1] | passed | 0.00007 seconds |
41
+ ./spec/mdspell/text_line_spec.rb[1:5:1] | passed | 0.0004 seconds |
42
+ ./spec/mdspell/text_line_spec.rb[1:6:1] | passed | 0.00015 seconds |
43
+ ./spec/mdspell/text_line_spec.rb[1:6:2:1] | passed | 0.00039 seconds |
25
44
  ./spec/mdspell/text_line_spec.rb[1:6:3:1] | passed | 0.00011 seconds |
26
45
  ./spec/mdspell/text_line_spec.rb[1:6:3:2] | passed | 0.0001 seconds |
27
- ./spec/mdspell/text_line_spec.rb[1:6:4:1] | passed | 0.00009 seconds |
28
- ./spec/mdspell/text_line_spec.rb[1:7:1] | passed | 0.00012 seconds |
29
- ./spec/mdspell/text_line_spec.rb[1:7:2] | passed | 0.00086 seconds |
30
- ./spec/mdspell/typo_spec.rb[1:1:1] | passed | 0.00011 seconds |
31
- ./spec/mdspell/typo_spec.rb[1:1:2] | passed | 0.0001 seconds |
46
+ ./spec/mdspell/text_line_spec.rb[1:6:4:1] | passed | 0.00043 seconds |
47
+ ./spec/mdspell/text_line_spec.rb[1:7:1] | passed | 0.00011 seconds |
48
+ ./spec/mdspell/text_line_spec.rb[1:7:2] | passed | 0.00094 seconds |
49
+ ./spec/mdspell/typo_spec.rb[1:1:1] | passed | 0.00052 seconds |
50
+ ./spec/mdspell/typo_spec.rb[1:1:2] | passed | 0.00009 seconds |
32
51
  ./spec/mdspell/typo_spec.rb[1:1:3] | passed | 0.00008 seconds |
33
- ./spec/mdspell/typo_spec.rb[1:2:1] | passed | 0.00012 seconds |
34
- ./spec/mdspell/typo_spec.rb[1:2:2] | passed | 0.00016 seconds |
52
+ ./spec/mdspell/typo_spec.rb[1:2:1] | passed | 0.00097 seconds |
53
+ ./spec/mdspell/typo_spec.rb[1:2:2] | passed | 0.00013 seconds |
35
54
  ./spec/mdspell/typo_spec.rb[1:2:3] | passed | 0.00014 seconds |
36
- ./spec/mdspell/typo_spec.rb[1:3:1] | passed | 0.00044 seconds |
37
- ./spec/mdspell/typo_spec.rb[1:4:1] | passed | 0.00007 seconds |
38
- ./spec/mdspell/typo_spec.rb[1:5:1] | passed | 0.00008 seconds |
39
- ./spec/mdspell/typo_spec.rb[1:5:2] | passed | 0.0001 seconds |
55
+ ./spec/mdspell/typo_spec.rb[1:3:1] | passed | 0.00042 seconds |
56
+ ./spec/mdspell/typo_spec.rb[1:4:1] | passed | 0.00016 seconds |
57
+ ./spec/mdspell/typo_spec.rb[1:5:1] | passed | 0.00028 seconds |
58
+ ./spec/mdspell/typo_spec.rb[1:5:2] | passed | 0.00034 seconds |
@@ -0,0 +1 @@
1
+ language 'pl'
@@ -0,0 +1,50 @@
1
+ describe MdSpell::CLI do
2
+ it { is_expected.to respond_to :run }
3
+ it { is_expected.to respond_to :files }
4
+
5
+ after(:all) do
6
+ MdSpell::Configuration.reset
7
+ end
8
+
9
+ context '#run' do
10
+ it 'should expect command line options array' do
11
+ [nil, 'string', 42].each do |argument|
12
+ expect do
13
+ subject.run(argument)
14
+ end.to raise_error ArgumentError, 'expected Array of command line options'
15
+ end
16
+ end
17
+ end
18
+
19
+ context '#files' do
20
+ context 'if single file given' do
21
+ it 'should return its path' do
22
+ subject.run(['README.md'])
23
+ expect(subject.files).to have(1).item
24
+
25
+ expect(subject.files[0]).to eq 'README.md'
26
+ end
27
+ end
28
+
29
+ context 'if directory given' do
30
+ it 'should return all markdown files in that directory' do
31
+ subject.run(['spec/examples'])
32
+ expect(subject.files).to have(2).item
33
+
34
+ expect(subject.files).to include('spec/examples/with_errors.md')
35
+ expect(subject.files).to include('spec/examples/simple.md')
36
+ end
37
+ end
38
+
39
+ context 'if both directory and single file given' do
40
+ it 'should return all files' do
41
+ subject.run(['README.md', 'spec/examples'])
42
+ expect(subject.files).to have(3).item
43
+
44
+ expect(subject.files).to include('spec/examples/with_errors.md')
45
+ expect(subject.files).to include('spec/examples/simple.md')
46
+ expect(subject.files).to include('README.md')
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,98 @@
1
+ describe MdSpell::Configuration do
2
+ before(:each) do
3
+ MdSpell::Configuration.reset
4
+ end
5
+
6
+ after(:all) do
7
+ MdSpell::Configuration.reset
8
+ end
9
+
10
+ def run_app(args = [])
11
+ MdSpell::CLI.new.run(args)
12
+ end
13
+
14
+ context ':config_file' do
15
+ it "should default to '~/.mdspell'" do
16
+ run_app
17
+ expect(MdSpell::Configuration[:config_file]).to eq '~/.mdspell'
18
+ end
19
+
20
+ context 'command line argument' do
21
+ it "uses '-c' short flag" do
22
+ run_app(['-c', 'short'])
23
+ expect(MdSpell::Configuration[:config_file]).to eq 'short'
24
+ end
25
+
26
+ it "uses '--config' long flag" do
27
+ run_app(['--config', 'long'])
28
+ expect(MdSpell::Configuration[:config_file]).to eq 'long'
29
+ end
30
+ end
31
+
32
+ context 'if file exists' do
33
+ it 'should merge its content' do
34
+ run_app(['-c', 'spec/examples/mdspell.config'])
35
+ expect(MdSpell::Configuration[:language]).to eq 'pl'
36
+ end
37
+ end
38
+ end
39
+
40
+ context ':language' do
41
+ it "should default to 'en_US'" do
42
+ run_app
43
+ expect(MdSpell::Configuration[:language]).to eq 'en_US'
44
+ end
45
+
46
+ context 'command line argument' do
47
+ it "uses '-l' short flag" do
48
+ run_app(['-l', 'en_GB'])
49
+ expect(MdSpell::Configuration[:language]).to eq 'en_GB'
50
+ end
51
+
52
+ it "uses '--language' long flag" do
53
+ run_app(['--language', 'uk'])
54
+ expect(MdSpell::Configuration[:language]).to eq 'uk'
55
+ end
56
+ end
57
+ end
58
+
59
+ context ':verbose' do
60
+ it 'should default to false' do
61
+ run_app
62
+ expect(MdSpell::Configuration[:verbose]).to eq false
63
+ end
64
+
65
+ context 'command line argument' do
66
+ it "uses '-v' short flag" do
67
+ run_app(['-v'])
68
+ expect(MdSpell::Configuration[:verbose]).to eq true
69
+ end
70
+
71
+ it "uses '--verbose' long flag" do
72
+ run_app(['--verbose'])
73
+ expect(MdSpell::Configuration[:verbose]).to eq true
74
+ end
75
+ end
76
+ end
77
+
78
+ context ':version' do
79
+ it 'should return proper string' do
80
+ run_app
81
+ expect(MdSpell::Configuration[:version]).to eq MdSpell::VERSION
82
+ end
83
+
84
+ context 'command line argument' do
85
+ it "uses '-V' short flag" do
86
+ expect do
87
+ run_app(['-V'])
88
+ end.to raise_error SystemExit
89
+ end
90
+
91
+ it "uses '--version' long flag" do
92
+ expect do
93
+ run_app(['--version'])
94
+ end.to raise_error SystemExit
95
+ end
96
+ end
97
+ end
98
+ end
@@ -37,7 +37,7 @@ describe MdSpell::SpellChecker do
37
37
 
38
38
  context 'if initialized from stdin' do
39
39
  it "should return 'stdin'" do
40
- expect(stdin_md.filename).to eq 'stdin'
40
+ expect(from_stdin.filename).to eq 'stdin'
41
41
  end
42
42
  end
43
43
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mdspell
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marek Tuchowski
@@ -57,8 +57,11 @@ files:
57
57
  - lib/mdspell/typo.rb
58
58
  - lib/mdspell/version.rb
59
59
  - spec/examples.cache
60
+ - spec/examples/mdspell.config
60
61
  - spec/examples/simple.md
61
62
  - spec/examples/with_errors.md
63
+ - spec/mdspell/cli_spec.rb
64
+ - spec/mdspell/configuration_spec.rb
62
65
  - spec/mdspell/spell_checker_spec.rb
63
66
  - spec/mdspell/text_line_spec.rb
64
67
  - spec/mdspell/typo_spec.rb
@@ -92,7 +95,10 @@ summary: A Ruby markdown spell checking tool.
92
95
  test_files:
93
96
  - spec/spec_helper.rb
94
97
  - spec/examples/with_errors.md
98
+ - spec/examples/mdspell.config
95
99
  - spec/examples/simple.md
100
+ - spec/mdspell/configuration_spec.rb
101
+ - spec/mdspell/cli_spec.rb
96
102
  - spec/mdspell/text_line_spec.rb
97
103
  - spec/mdspell/typo_spec.rb
98
104
  - spec/mdspell/spell_checker_spec.rb