pronto-clang_format 0.1.3 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +7 -0
- data/README.md +43 -2
- data/Rakefile +4 -0
- data/lib/pronto/clang_format/offence_categorizer/abstract_categorizer.rb +7 -3
- data/lib/pronto/clang_format/offence_categorizer/factory.rb +5 -3
- data/lib/pronto/clang_format/offence_categorizer/includes_order_categorizer.rb +2 -2
- data/lib/pronto/clang_format/offence_categorizer/indentation_categorizer.rb +3 -1
- data/lib/pronto/clang_format/offence_categorizer/missing_newline_categorizer.rb +17 -0
- data/lib/pronto/clang_format/offence_categorizer/trailing_whitespace_categorizer.rb +15 -0
- data/lib/pronto/clang_format/offence_categorizer/unnecessary_newline_categorizer.rb +15 -0
- data/lib/pronto/clang_format/offence_categorizer/using_order_categorizer.rb +15 -0
- data/lib/pronto/clang_format/version.rb +1 -1
- data/pronto-clang_format.gemspec +1 -0
- metadata +21 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 49f3c645df42fafe96470903b922f1f9cbaf902183cdea14649a0c00ddd48999
|
4
|
+
data.tar.gz: 986aadc6c598c278c0c31102092b96d4b68002ade949fef885836be9e4f9fd4d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 59cc1f84ddaea0c4d4238af82912853c3b96adfe94f5e8b198edacfb63546d47a1241c1fdb5994597aad82930559ec34bd8d9dc5de5b5f3f7a8870674545a21a
|
7
|
+
data.tar.gz: 52fa9526d57234ee6ed2a146360c2bc2d7ce2a759064cd6718ea7713446391aa6fd6eee8825bf0d770ef27226ce127966050082e50b85aadc35eff3b3ac39600
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,3 +1,44 @@
|
|
1
|
-
|
1
|
+
# Pronto runner for clang-format
|
2
2
|
|
3
|
-
|
3
|
+
[![Code Climate](https://codeclimate.com/github/micjabbour/pronto-clang_format.png)](https://codeclimate.com/github/micjabbour/pronto-clang_format)
|
4
|
+
[![Build Status](https://travis-ci.org/micjabbour/pronto-clang_format.png)](https://travis-ci.org/micjabbour/pronto-clang_format)
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/pronto-clang_format.png)](http://badge.fury.io/rb/pronto-clang_format)
|
6
|
+
[![Dependency Status](https://gemnasium.com/micjabbour/pronto-clang_format.png)](https://gemnasium.com/micjabbour/pronto-clang_format)
|
7
|
+
|
8
|
+
Pronto runner for [clang-format](https://clang.llvm.org/docs/ClangFormat.html), a tool to reformat C/C++/Java/JavaScript/Objective-C/Protobuf code according to configurable style guidelines. [What is Pronto?](https://github.com/prontolabs/pronto)
|
9
|
+
|
10
|
+
As an example, this can be used to run clang-format and submit replacements to web-based git repo managers (e.g. github, gitlab, ...) as comments using Pronto.
|
11
|
+
|
12
|
+
## Installation:
|
13
|
+
|
14
|
+
First, the following prerequisites need to be installed:
|
15
|
+
|
16
|
+
1. clang-format
|
17
|
+
2. Ruby
|
18
|
+
3. Pronto, this can be done after installing Ruby using:
|
19
|
+
```
|
20
|
+
gem install pronto
|
21
|
+
```
|
22
|
+
After that, pronto-clang_format can be installed using:
|
23
|
+
```
|
24
|
+
gem install pronto-clang_format
|
25
|
+
```
|
26
|
+
Pronto will detect and run clang-format as soon as this runner is installed.
|
27
|
+
|
28
|
+
## Configuration:
|
29
|
+
|
30
|
+
The runner can be configured by setting some environment variables before invoking it. The following table lists these environment
|
31
|
+
variables along with a description for each one of them:
|
32
|
+
|
33
|
+
| Environment variable | Description |
|
34
|
+
|:-------------------------------|:------------------------------------------------------------------------------------------------------|
|
35
|
+
| `PRONTO_CLANG_FORMAT_PATH` | Path to the clang-format executable that should be run by the runner. This defaults to `clang-format` |
|
36
|
+
| `PRONTO_CLANG_FORMAT_STYLE` | A string that is passed to clang-format's `--style=` option. This defaults to `file` |
|
37
|
+
| `PRONTO_CLANG_FORMAT_FILE_EXTS`| A comma separated list of file extensions to examine. This defaults to `c, h, cpp, cc, cxx, c++, hh, hxx, hpp, h++, icc, inl, tcc, tpp, ipp`|
|
38
|
+
|
39
|
+
|
40
|
+
## Known limitations:
|
41
|
+
* Every replacement reported by clang-format is mapped to no more than one offence, even though the reported replacement might be fixing more than one offence (e.g. trailing whitespace in a line and improper indentation in the following line)
|
42
|
+
* Only one offence is reported per line; to avoid overwhelming one line with too many offences
|
43
|
+
* Categorizers are rudimentary, but more can be added easily to the current chain
|
44
|
+
* This runner is mostly meant to remind the developer to run clang-format on his changed files. It is not about going through the offences one by one and fixing them manually
|
data/Rakefile
CHANGED
@@ -1,12 +1,16 @@
|
|
1
1
|
module Pronto
|
2
2
|
module ClangFormat
|
3
3
|
module OffenceCategorizer
|
4
|
-
# base class to implement a chain of
|
4
|
+
# base class to implement a chain of categorizers
|
5
5
|
class AbstractCategorizer
|
6
6
|
def initialize(successor = nil)
|
7
7
|
@successor = successor
|
8
8
|
end
|
9
9
|
|
10
|
+
# Tries to handle the offence using the current categorizer. If it
|
11
|
+
# couldn't, it passes the offence to the next categorizer in the chain.
|
12
|
+
# If this is the last categorizer in the chain, it returns a generic
|
13
|
+
# message
|
10
14
|
def handle(offence)
|
11
15
|
current_result = handle_current offence
|
12
16
|
if !current_result.nil?
|
@@ -14,8 +18,8 @@ module Pronto
|
|
14
18
|
elsif !@successor.nil?
|
15
19
|
@successor.handle offence
|
16
20
|
else # unahndled offence
|
17
|
-
"This should be rewritten as: \n
|
18
|
-
"
|
21
|
+
"Improper formatting. This should be rewritten as: \n" \
|
22
|
+
"```#{offence.affected_lines_after}```"
|
19
23
|
end
|
20
24
|
end
|
21
25
|
|
@@ -1,12 +1,14 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# require all ruby files in the current directory (all categorizers)
|
2
|
+
Dir[File.join(__dir__, '*.rb')].each { |file| require file }
|
3
3
|
|
4
4
|
module Pronto
|
5
5
|
module ClangFormat
|
6
6
|
module OffenceCategorizer
|
7
7
|
class Factory
|
8
8
|
def self.create_categorizers
|
9
|
-
IncludesOrderCategorizer.new
|
9
|
+
IncludesOrderCategorizer.new UsingOrderCategorizer.new \
|
10
|
+
UnnecessaryNewlineCategorizer.new IndentationCategorizer.new \
|
11
|
+
MissingNewlineCategorizer.new TrailingWhitespaceCategorizer.new
|
10
12
|
end
|
11
13
|
end
|
12
14
|
end
|
@@ -8,8 +8,8 @@ module Pronto
|
|
8
8
|
return unless offence.replaced_text.include? 'include'
|
9
9
|
|
10
10
|
"Include statements are not ordered alphabetically. "\
|
11
|
-
"They should be rewritten as:\n
|
12
|
-
"
|
11
|
+
"They should be rewritten as:\n" \
|
12
|
+
"```#{offence.affected_lines_after}```"
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require_relative 'abstract_categorizer'
|
2
|
+
|
3
|
+
module Pronto
|
4
|
+
module ClangFormat
|
5
|
+
module OffenceCategorizer
|
6
|
+
class MissingNewlineCategorizer < AbstractCategorizer
|
7
|
+
def handle_current(offence)
|
8
|
+
return unless offence.replaced_text.count("\n") \
|
9
|
+
< offence.replacement.count("\n")
|
10
|
+
|
11
|
+
"Missing newline. This should be rewritten as:\n" \
|
12
|
+
"```#{offence.affected_lines_after}```"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require_relative 'abstract_categorizer'
|
2
|
+
|
3
|
+
module Pronto
|
4
|
+
module ClangFormat
|
5
|
+
module OffenceCategorizer
|
6
|
+
class TrailingWhitespaceCategorizer < AbstractCategorizer
|
7
|
+
def handle_current(offence)
|
8
|
+
return unless /[[:blank:]]+[\n]/.match(offence.replaced_text)
|
9
|
+
|
10
|
+
"Remove trailing whitespace"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require_relative 'abstract_categorizer'
|
2
|
+
|
3
|
+
module Pronto
|
4
|
+
module ClangFormat
|
5
|
+
module OffenceCategorizer
|
6
|
+
class UnnecessaryNewlineCategorizer < AbstractCategorizer
|
7
|
+
def handle_current(offence)
|
8
|
+
return unless offence.column == 0
|
9
|
+
|
10
|
+
"Unnecessary new line"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require_relative 'abstract_categorizer'
|
2
|
+
|
3
|
+
module Pronto
|
4
|
+
module ClangFormat
|
5
|
+
module OffenceCategorizer
|
6
|
+
class UsingOrderCategorizer < AbstractCategorizer
|
7
|
+
def handle_current(offence)
|
8
|
+
return unless offence.replaced_text.include? 'using'
|
9
|
+
|
10
|
+
"Using declarations not ordered alphabetically"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/pronto-clang_format.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pronto-clang_format
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Jabbour
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-05-
|
11
|
+
date: 2018-05-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pronto
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.4'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.4'
|
55
69
|
description:
|
56
70
|
email:
|
57
71
|
- micjabbour@gmail.com
|
@@ -62,6 +76,7 @@ extra_rdoc_files:
|
|
62
76
|
- README.md
|
63
77
|
files:
|
64
78
|
- ".gitignore"
|
79
|
+
- ".travis.yml"
|
65
80
|
- Gemfile
|
66
81
|
- LICENSE.txt
|
67
82
|
- README.md
|
@@ -72,6 +87,10 @@ files:
|
|
72
87
|
- lib/pronto/clang_format/offence_categorizer/factory.rb
|
73
88
|
- lib/pronto/clang_format/offence_categorizer/includes_order_categorizer.rb
|
74
89
|
- lib/pronto/clang_format/offence_categorizer/indentation_categorizer.rb
|
90
|
+
- lib/pronto/clang_format/offence_categorizer/missing_newline_categorizer.rb
|
91
|
+
- lib/pronto/clang_format/offence_categorizer/trailing_whitespace_categorizer.rb
|
92
|
+
- lib/pronto/clang_format/offence_categorizer/unnecessary_newline_categorizer.rb
|
93
|
+
- lib/pronto/clang_format/offence_categorizer/using_order_categorizer.rb
|
75
94
|
- lib/pronto/clang_format/version.rb
|
76
95
|
- lib/pronto/clang_format/wrapper.rb
|
77
96
|
- lib/pronto/clang_format_runner.rb
|