texsc 0.1.0 → 0.4.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
  SHA256:
3
- metadata.gz: e32f01e9713f452e0ed430e1b86a0336b60c124493f97c3e85534c9ccb82ecb4
4
- data.tar.gz: 969342bbe56d241096a82504328def1a22567779c1f6b97793da92c6c3b6691e
3
+ metadata.gz: 66cf2c3cd1fdf24062daf97f76e2a1d2a9bbc7496d4de4b110863fa9a05e34f7
4
+ data.tar.gz: 9482805d7979f80530858c721bcccb1cc80f9b01a59edf3c79e320a22979a90a
5
5
  SHA512:
6
- metadata.gz: 7ea846d38263b985dd1f4e8fc701848e7fba88a661852d1e5aaeb265ca55967544e6ccc1994fadec7e4f5c8542d3743fb8d05c5df1feef795a1b639c124d85d0
7
- data.tar.gz: a0e9b64259720b8e39b321de67e99384865a7f2b7c0220e44b5d736b9beef1fe44aad56338177411d61799ad89359a701eda2f54d7550306955eb89ef024c481
6
+ metadata.gz: 37f58dc30b1ccadd1edf187b5264d2f95d078c9502ab946711728c88f08bde644dd78a8285b25cec7f793ea5103cf5c8657e5b312fb04000068e1ed429bb19a6
7
+ data.tar.gz: 7477be10ec95d87d4a39429fedb65fa132227afa3b14c5238a5e470eaf7e64f9248473cb92d9e3306c5d8f75ad0cb22cb88c2ef0b12075b09dd003d85941e94a
@@ -4,29 +4,15 @@ AllCops:
4
4
  DisplayCopNames: true
5
5
  TargetRubyVersion: 2.3
6
6
 
7
- Style/ClassAndModuleChildren:
8
- Enabled: false
9
7
  Metrics/LineLength:
10
8
  Max: 100
11
9
  Layout/EndOfLine:
12
10
  EnforcedStyle: lf
13
- Metrics/CyclomaticComplexity:
14
- Max: 20
15
- Metrics/MethodLength:
16
- Enabled: false
17
- Layout/MultilineMethodCallIndentation:
18
- Enabled: false
19
- Metrics/ParameterLists:
20
- Max: 6
21
- Metrics/ClassLength:
22
- Max: 250
23
- Metrics/AbcSize:
11
+ Style/MultilineTernaryOperator:
24
12
  Enabled: false
25
13
  Metrics/BlockLength:
26
- Max: 100
27
- Metrics/PerceivedComplexity:
28
- Max: 20
29
- Style/MultilineTernaryOperator:
14
+ Max: 50
15
+ Layout/AlignParameters:
30
16
  Enabled: false
31
17
  Layout/EmptyLineAfterGuardClause:
32
18
  Enabled: false
@@ -1,6 +1,7 @@
1
1
  assets:
2
2
  rubygems.yml: yegor256/home#assets/rubygems.yml
3
3
  install: |
4
+ sudo apt install -y aspell
4
5
  pdd -f /dev/null
5
6
  sudo bundle install --no-color "--gemfile=$(pwd)/Gemfile"
6
7
  release:
@@ -5,6 +5,11 @@ cache: bundler
5
5
  branches:
6
6
  only:
7
7
  - master
8
+ addons:
9
+ apt:
10
+ packages:
11
+ - aspell
12
+ - aspell-en
8
13
  install:
9
14
  - gem install pdd -v 0.20.5
10
15
  - travis_retry bundle update
data/README.md CHANGED
@@ -8,18 +8,53 @@
8
8
  [![Build Status](https://travis-ci.org/yegor256/texsc.svg)](https://travis-ci.org/yegor256/texsc)
9
9
  [![PDD status](http://www.0pdd.com/svg?name=yegor256/texsc)](http://www.0pdd.com/p?name=yegor256/texsc)
10
10
  [![Gem Version](https://badge.fury.io/rb/texsc.svg)](http://badge.fury.io/rb/texsc)
11
- [![Maintainability](https://api.codeclimate.com/v1/badges/74c909f06d4afa0d8001/maintainability)](https://codeclimate.com/github/yegor256/texsc/maintainability)
11
+ [![Maintainability](https://api.codeclimate.com/v1/badges/7593273bfae71f87ea8c/maintainability)](https://codeclimate.com/github/yegor256/texsc/maintainability)
12
12
 
13
13
  [![License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/yegor256/takes/texsc/master/LICENSE.txt)
14
14
  [![Test Coverage](https://img.shields.io/codecov/c/github/yegor256/texsc.svg)](https://codecov.io/github/yegor256/texsc?branch=master)
15
15
  [![Hits-of-Code](https://hitsofcode.com/github/yegor256/texsc)](https://hitsofcode.com/view/github/yegor256/texsc)
16
16
 
17
- Just run it like this for your LaTeX file:
17
+ This tool simplies the usage of [GNU aspell](http://aspell.net/)
18
+ (you must have it installed)
19
+ for spell-checking of LaTeX files.
20
+
21
+ First, you install it:
22
+
23
+ ```bash
24
+ $ gem install texsc
25
+ ```
26
+
27
+ Then, you just run it like this for your LaTeX files:
18
28
 
19
29
  ```bash
20
30
  $ texsc article.tex
21
31
  ```
22
32
 
33
+ You may ignore certain tags or environments using `--ignore` option
34
+
35
+ ```bash
36
+ $ texsc --ignore=citet,citep --ignore=newminted article.tex
37
+ ```
38
+
39
+ You can specify the method of ignoring,
40
+ as [aspell suggests](http://aspell.net/man-html/The-Options.html#TeX_002fLaTeX-Filter)
41
+ (by default it's 'p'):
42
+
43
+ ```bash
44
+ $ texsc --ignore=newminted:opp article.tex
45
+ ```
46
+
47
+ You may also use your own additional dictionary, via `--pws` option.
48
+ The file must contain one word per line:
49
+ they will be ignored during spell checking. Don't forget that
50
+ the first line of the file
51
+ [must contain](http://aspell.net/man-html/Format-of-the-Personal-and-Replacement-Dictionaries.html)
52
+ this:
53
+
54
+ ```
55
+ personal_ws-1.1 en 1 utf-8
56
+ ```
57
+
23
58
  ## How to contribute
24
59
 
25
60
  Read [these guidelines](https://www.yegor256.com/2014/04/15/github-guidelines.html).
data/bin/texsc CHANGED
@@ -21,7 +21,7 @@
21
21
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
22
  # SOFTWARE.
23
23
 
24
- VERSION = '0.1.0'
24
+ VERSION = '0.4.0'
25
25
 
26
26
  STDOUT.sync = true
27
27
 
@@ -38,6 +38,8 @@ begin
38
38
  Options are:"
39
39
  o.string '--pws', 'The location of aspell.en.pws file'
40
40
  o.array '--ignore', 'The name of the command or environment to ignore'
41
+ o.integer '--min-word-length',
42
+ 'The minimum length of the word to be checked', default: 3
41
43
  o.bool '--version', 'Print current version' do
42
44
  puts VERSION
43
45
  exit
@@ -60,37 +62,62 @@ Options are:"
60
62
  log.debug("The real path of PWS is: #{opts[:pws]}")
61
63
  end
62
64
  errors = 0
65
+ files = 0
63
66
  opts.arguments.each do |f|
64
67
  tex = File.read(f)
65
- opts[:ignore].each do |e|
66
- tex = tex.gsub(/\\begin{#{e}}.+\\end{#{e}}/m, '')
68
+ ignores = opts[:ignore].map do |e|
69
+ c, o = e.split(':')
70
+ { cmd: c, opts: o || 'p' }
71
+ end
72
+ ignores.each do |i|
73
+ tex = tex.gsub(/\\begin{#{Regexp.escape(i[:cmd])}}.+\\end{#{Regexp.escape(i[:cmd])}}/m, '')
67
74
  end
68
75
  log.info("Checking #{f} (#{tex.length} chars)...")
76
+ log.debug(
77
+ tex.split("\n")
78
+ .each_with_index.map { |t, i| format('%<pos>4d: %<line>s', pos: i + 1, line: t) }
79
+ .join("\n")
80
+ )
69
81
  cmd = [
70
82
  'aspell',
71
- '--ignore=3',
83
+ "--ignore=#{opts['min-word-length']}",
72
84
  '--dont-tex-check-comments',
73
85
  '--lang=en',
74
86
  '--mode=tex',
75
87
  opts[:pws] ? "-p #{opts[:pws]}" : '',
76
- opts[:ignore].map { |e| "--add-tex-command '#{e} p'" }.join(' '),
88
+ ignores.map { |i| "--add-tex-command '#{i[:cmd]} #{i[:opts]}'" }.join(' '),
77
89
  'pipe'
78
90
  ].join(' ')
79
91
  log.debug(cmd)
80
- Open3.popen3(cmd) do |stdin, stdout, _stderr, _thread|
92
+ Open3.popen3(cmd) do |stdin, stdout, stderr, thread|
81
93
  stdin.print(tex)
82
94
  stdin.close
83
- stdout.read.split("\n").select { |t| t.start_with?('&') }.each do |t|
84
- log.info(t)
85
- errors += 1
95
+ status = thread.value.to_i
96
+ unless status.zero?
97
+ log.error(stderr.read)
98
+ raise "Failed to run aspell, exit code is #{status}"
99
+ end
100
+ out = stdout.read
101
+ if out.nil?
102
+ log.info('aspell produced no output, hm...')
103
+ else
104
+ lines = out.split("\n")
105
+ log.info("aspell produced #{lines.length} lines of output")
106
+ lines.each_with_index do |t, i|
107
+ if t.start_with?('&')
108
+ log.info("[#{i}] #{t}")
109
+ errors += 1
110
+ end
111
+ end
86
112
  end
87
113
  end
114
+ files += 1
88
115
  end
89
116
  unless errors.zero?
90
- log.info("#{errors} spelling errors found")
117
+ log.info("#{errors} spelling errors found in #{files} file(s)")
91
118
  exit 1
92
119
  end
93
- log.info('No spelling errors found, the text is clean')
120
+ log.info("No spelling errors found in #{files} file(s), the text is clean")
94
121
  rescue StandardError => ex
95
122
  if opts[:verbose]
96
123
  puts Backtrace.new(ex).to_s
@@ -6,3 +6,115 @@ Feature: Command Line Processing
6
6
  Then Exit code is zero
7
7
  And Stdout contains "--help"
8
8
 
9
+ Scenario: Good LaTeX can be spell checked
10
+ Given I have a "article.tex" file with content:
11
+ """
12
+ \documentclass{article}
13
+ \begin{document}
14
+ How are you, my dear friend?
15
+ \end{document}
16
+ """
17
+ When I run bin/texsc with "article.tex"
18
+ Then Exit code is zero
19
+ And Stdout contains "No spelling errors found in 1 file(s)"
20
+
21
+ Scenario: Bad LaTeX can be spell checked
22
+ Given I have a "article.tex" file with content:
23
+ """
24
+ \documentclass{article}
25
+ \begin{document}
26
+ How are you, my dear friiend?
27
+ \end{document}
28
+ """
29
+ When I run bin/texsc with "--verbose article.tex"
30
+ Then Exit code is not zero
31
+ And Stdout contains "& friiend "
32
+
33
+ Scenario: Bad LaTeX with PWS can be spell checked
34
+ Given I have a "article.tex" file with content:
35
+ """
36
+ \documentclass{article}
37
+ \begin{document}
38
+ How are you, my dear friiend?
39
+ \end{document}
40
+ """
41
+ And I have a "aspell.en.pws" file with content:
42
+ """
43
+ personal_ws-1.1 en 1 utf-8
44
+ hello
45
+ friiend
46
+ """
47
+ When I run bin/texsc with "--pws aspell.en.pws article.tex"
48
+ Then Exit code is zero
49
+
50
+ Scenario: Bad LaTeX with broken PWS can be spell checked
51
+ Given I have a "article.tex" file with content:
52
+ """
53
+ \documentclass{article}
54
+ \begin{document}
55
+ How are you, my dear friiend?
56
+ \end{document}
57
+ """
58
+ And I have a "aspell.en.pws" file with content:
59
+ """
60
+ friiend
61
+ """
62
+ When I run bin/texsc with "--pws aspell.en.pws article.tex"
63
+ Then Exit code is not zero
64
+ And Stdout contains "is not in the proper format"
65
+
66
+ Scenario: Bad LaTeX with --ignore can be spell checked
67
+ Given I have a "article.tex" file with content:
68
+ """
69
+ \documentclass{article}
70
+ \begin{document}
71
+ How are you, my dear \nospell{friiend}?
72
+ \end{document}
73
+ """
74
+ When I run bin/texsc with "--ignore nospell article.tex"
75
+ Then Exit code is zero
76
+
77
+ Scenario: Bad LaTeX with complex --ignore can be spell checked
78
+ Given I have a "article.tex" file with content:
79
+ """
80
+ \documentclass{article}
81
+ \begin{document}
82
+ How are you, my dear \nospell[friiend]{friiend}{friiend}?
83
+ \end{document}
84
+ """
85
+ When I run bin/texsc with "--ignore nospell:opp article.tex"
86
+ Then Exit code is zero
87
+
88
+ Scenario: Bad LaTeX with complex --ignore can be spell checked
89
+ Given I have a "article.tex" file with content:
90
+ """
91
+ \documentclass{article}
92
+ \begin{document}
93
+ How are you, \begin{nospell}{test}friiend\end{nospell}?
94
+ \end{document}
95
+ """
96
+ When I run bin/texsc with "--ignore nospell:p article.tex"
97
+ Then Exit code is zero
98
+
99
+ Scenario: Bad LaTeX with complex --ignore can be spell checked
100
+ Given I have a "article.tex" file with content:
101
+ """
102
+ \documentclass{article}
103
+ \begin{document}
104
+ How are you, \begin{Nospell*}{test}friiend\end{Nospell*}?
105
+ \end{document}
106
+ """
107
+ When I run bin/texsc with "--ignore Nospell*:p article.tex"
108
+ Then Exit code is zero
109
+
110
+ Scenario: Bad LaTeX with too short words can be spell checked
111
+ Given I have a "article.tex" file with content:
112
+ """
113
+ \documentclass{article}
114
+ \begin{document}
115
+ How are you, my dear ZZZZ?
116
+ \end{document}
117
+ """
118
+ When I run bin/texsc with "--min-word-length=4 article.tex"
119
+ Then Exit code is zero
120
+
@@ -32,7 +32,7 @@ Gem::Specification.new do |s|
32
32
  s.rubygems_version = '2.2'
33
33
  s.required_ruby_version = '>= 2.3'
34
34
  s.name = 'texsc'
35
- s.version = '0.1.0'
35
+ s.version = '0.4.0'
36
36
  s.license = 'MIT'
37
37
  s.summary = 'Spell Checker for LaTeX'
38
38
  s.description = 'Simple command-line spell checker for LaTeX documents'
@@ -47,7 +47,7 @@ Gem::Specification.new do |s|
47
47
  s.add_runtime_dependency 'backtrace', '~> 0.3'
48
48
  s.add_runtime_dependency 'loog', '~> 0.2'
49
49
  s.add_runtime_dependency 'slop', '~> 4.6'
50
- s.add_development_dependency 'codecov', '0.1.10'
50
+ s.add_development_dependency 'codecov', '0.2.8'
51
51
  s.add_development_dependency 'cucumber', '~> 1.3.17'
52
52
  s.add_development_dependency 'rake', '12.0.0'
53
53
  s.add_development_dependency 'rubocop', '0.61.0'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: texsc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-01 00:00:00.000000000 Z
11
+ date: 2020-08-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backtrace
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - '='
60
60
  - !ruby/object:Gem::Version
61
- version: 0.1.10
61
+ version: 0.2.8
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - '='
67
67
  - !ruby/object:Gem::Version
68
- version: 0.1.10
68
+ version: 0.2.8
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: cucumber
71
71
  requirement: !ruby/object:Gem::Requirement