mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
New rule: Line Length
This commit is contained in:
parent
eb367c682e
commit
4e84ac871a
4 changed files with 62 additions and 13 deletions
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
|
||||
|
||||
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
|
||||
|
|
23
src/ameba.cr
23
src/ameba.cr
|
@ -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
|
||||
|
|
9
src/ameba/rule/line_length.cr
Normal file
9
src/ameba/rule/line_length.cr
Normal 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
10
src/ameba/source.cr
Normal 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
|
Loading…
Reference in a new issue