diff --git a/README.md b/README.md index c655c644..0fec5a36 100644 --- a/README.md +++ b/README.md @@ -1,32 +1,41 @@ -# ameba +

+ +

Ameba

+

Code style linter for Crystal

+

+ + + (a single-celled animal that catches food and moves about by extending fingerlike projections of protoplasm) + + +

+

-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 diff --git a/src/ameba.cr b/src/ameba.cr index 11c92400..3a5bc6b2 100644 --- a/src/ameba.cr +++ b/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 diff --git a/src/ameba/rule/line_length.cr b/src/ameba/rule/line_length.cr new file mode 100644 index 00000000..0b54dac9 --- /dev/null +++ b/src/ameba/rule/line_length.cr @@ -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 diff --git a/src/ameba/source.cr b/src/ameba/source.cr new file mode 100644 index 00000000..e2f0f08c --- /dev/null +++ b/src/ameba/source.cr @@ -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