New rule: Line Length

This commit is contained in:
Vitalii Elenhaupt 2017-10-26 20:47:42 +03:00
parent eb367c682e
commit 4e84ac871a
No known key found for this signature in database
GPG Key ID: 7558EF3A4056C706
4 changed files with 62 additions and 13 deletions

View File

@ -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
Add this to your application's `shard.yml`:
```yaml
dependencies:
development_dependencies:
ameba:
github: [your-github-name]/ameba
github: veelenga/ameba
```
## Usage
```crystal
require "ameba"
Ameba.run
```
TODO: Write usage instructions here
## Development
TODO: Write development instructions here
## 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)
3. Commit your changes (git commit -am 'Add some feature')
4. Push to the branch (git push origin my-new-feature)
@ -34,4 +43,4 @@ TODO: Write development instructions here
## Contributors
- [[your-github-name]](https://github.com/[your-github-name]) Vitalii Elenhaupt - creator, maintainer
- [veelenga](https://github.com/veelenga) Vitalii Elenhaupt - creator, maintainer

View File

@ -1,5 +1,26 @@
require "./ameba/*"
require "./ameba/rule/*"
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

View File

@ -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

10
src/ameba/source.cr Normal file
View File

@ -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