New rule: Line Length
This commit is contained in:
parent
eb367c682e
commit
4e84ac871a
33
README.md
33
README.md
|
@ -1,32 +1,41 @@
|
||||||
# ameba
|
<p align="center">
|
||||||
|
<img src="https://media.githubusercontent.com/media/veelenga/bin/master/ameba/logo.png" width="200">
|
||||||
|
<h3 align="center">Ameba</h3>
|
||||||
|
<p align="center">Code style linter for Crystal<p>
|
||||||
|
<p align="center">
|
||||||
|
<sup>
|
||||||
|
<i>
|
||||||
|
(a single-celled animal that catches food and moves about by extending fingerlike projections of protoplasm)
|
||||||
|
</i>
|
||||||
|
</sup>
|
||||||
|
</p>
|
||||||
|
</p>
|
||||||
|
|
||||||
TODO: Write a description here
|
## Status
|
||||||
|
|
||||||
|
**CONSTRUCTION ZONE** :construction:
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
Add this to your application's `shard.yml`:
|
Add this to your application's `shard.yml`:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
dependencies:
|
development_dependencies:
|
||||||
ameba:
|
ameba:
|
||||||
github: [your-github-name]/ameba
|
github: veelenga/ameba
|
||||||
```
|
```
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```crystal
|
```crystal
|
||||||
require "ameba"
|
require "ameba"
|
||||||
|
|
||||||
|
Ameba.run
|
||||||
```
|
```
|
||||||
|
|
||||||
TODO: Write usage instructions here
|
|
||||||
|
|
||||||
## Development
|
|
||||||
|
|
||||||
TODO: Write development instructions here
|
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
1. Fork it ( https://github.com/[your-github-name]/ameba/fork )
|
1. Fork it ( https://github.com/veelenga/ameba/fork )
|
||||||
2. Create your feature branch (git checkout -b my-new-feature)
|
2. Create your feature branch (git checkout -b my-new-feature)
|
||||||
3. Commit your changes (git commit -am 'Add some feature')
|
3. Commit your changes (git commit -am 'Add some feature')
|
||||||
4. Push to the branch (git push origin my-new-feature)
|
4. Push to the branch (git push origin my-new-feature)
|
||||||
|
@ -34,4 +43,4 @@ TODO: Write development instructions here
|
||||||
|
|
||||||
## Contributors
|
## Contributors
|
||||||
|
|
||||||
- [[your-github-name]](https://github.com/[your-github-name]) Vitalii Elenhaupt - creator, maintainer
|
- [veelenga](https://github.com/veelenga) Vitalii Elenhaupt - creator, maintainer
|
||||||
|
|
23
src/ameba.cr
23
src/ameba.cr
|
@ -1,5 +1,26 @@
|
||||||
require "./ameba/*"
|
require "./ameba/*"
|
||||||
|
require "./ameba/rule/*"
|
||||||
|
|
||||||
module Ameba
|
module Ameba
|
||||||
# TODO Put your code here
|
extend self
|
||||||
|
|
||||||
|
RULES = [
|
||||||
|
Rule::LineLength,
|
||||||
|
]
|
||||||
|
|
||||||
|
def run
|
||||||
|
run Dir["**/*.cr"]
|
||||||
|
end
|
||||||
|
|
||||||
|
def run(files)
|
||||||
|
files.each do |path|
|
||||||
|
catch Source.new(File.read path)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def catch(source : Source)
|
||||||
|
RULES.each do |rule|
|
||||||
|
rule.new.test(source)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
struct Ameba::Rule::LineLength
|
||||||
|
def test(source)
|
||||||
|
source.lines.each do |line|
|
||||||
|
if line.size > 79
|
||||||
|
source.errors << "Line too long"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,10 @@
|
||||||
|
module Ameba
|
||||||
|
class Source
|
||||||
|
getter lines : Array(String)
|
||||||
|
getter errors = [] of String
|
||||||
|
|
||||||
|
def initialize(content : String)
|
||||||
|
@lines = content.split "\n"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue