mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Usage info & exclude lib/ project folder
This commit is contained in:
parent
6ca4e38167
commit
628077066e
2 changed files with 43 additions and 14 deletions
55
README.md
55
README.md
|
@ -17,9 +17,12 @@
|
||||||
</p>
|
</p>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
## Status
|
## About
|
||||||
|
|
||||||
**CONSTRUCTION ZONE** :construction:
|
Ameba is a tool for enforcing a consistent Crystal code style, for catching code smells and wrong code constructions.
|
||||||
|
Ameba's [rules](src/ameba/rules/) traverse AST and report bad parts of your code.
|
||||||
|
|
||||||
|
Is still under construction, compatibility may be broken :construction:
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
|
@ -31,15 +34,16 @@ development_dependencies:
|
||||||
github: veelenga/ameba
|
github: veelenga/ameba
|
||||||
```
|
```
|
||||||
|
|
||||||
|
That will compile and install `ameba` binary onto your system.
|
||||||
|
|
||||||
|
Or just compile it from sources `make install`.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```crystal
|
Run `ameba` binary to catch code issues within you project:
|
||||||
require "ameba"
|
|
||||||
|
|
||||||
Ameba.run
|
|
||||||
```
|
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
|
$ ameba
|
||||||
Inspecting 18 files.
|
Inspecting 18 files.
|
||||||
|
|
||||||
|
|
||||||
|
@ -54,13 +58,38 @@ src/ameba.cr:12
|
||||||
UnlessElse: Favour if over unless with else
|
UnlessElse: Favour if over unless with else
|
||||||
```
|
```
|
||||||
|
|
||||||
## Contributing
|
## Write a new Rule
|
||||||
|
|
||||||
1. Fork it ( https://github.com/veelenga/ameba/fork )
|
Adding a new rule is as simple as inheriting from `Rule` struct and implementing
|
||||||
2. Create your feature branch (git checkout -b my-new-feature)
|
your logic to detect a problem:
|
||||||
3. Commit your changes (git commit -am 'Add some feature')
|
|
||||||
4. Push to the branch (git push origin my-new-feature)
|
```crystal
|
||||||
5. Create a new Pull Request
|
struct DebuggerStatement < Rule
|
||||||
|
# This is a required method to be implemented by the rule.
|
||||||
|
# Source will pass here. If rule finds an issue in this source,
|
||||||
|
# it adds an error:
|
||||||
|
#
|
||||||
|
# source.error rule, line_number, message
|
||||||
|
#
|
||||||
|
def test(source)
|
||||||
|
# This line deletegates verification to a particular AST visitor.
|
||||||
|
AST::CallVisitor.new self, source
|
||||||
|
end
|
||||||
|
|
||||||
|
# This method is called once our visitor finds a required node.
|
||||||
|
#
|
||||||
|
# It reports an error, once there is `debugger` method call
|
||||||
|
# without arguments and a receiver. That's it, somebody forgot
|
||||||
|
# to remove debugger statement.
|
||||||
|
def test(source, node : Crystal::Call)
|
||||||
|
return unless node.name == "debugger" && node.args.empty? && node.obj.nil?
|
||||||
|
|
||||||
|
source.error self, node.location.try &.line_number,
|
||||||
|
"Possible forgotten debugger statement detected"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
## Contributors
|
## Contributors
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ module Ameba
|
||||||
end
|
end
|
||||||
|
|
||||||
def run(formatter = DotFormatter.new)
|
def run(formatter = DotFormatter.new)
|
||||||
run Dir["**/*.cr"], formatter
|
run Dir["**/*.cr"].reject(&.starts_with? "lib/"), formatter
|
||||||
end
|
end
|
||||||
|
|
||||||
def run(files, formatter : Formatter)
|
def run(files, formatter : Formatter)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue