mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Add Naming/Filename
rule
This commit is contained in:
parent
881209d54e
commit
b9ce705a47
2 changed files with 47 additions and 0 deletions
19
spec/ameba/rule/naming/filename_spec.cr
Normal file
19
spec/ameba/rule/naming/filename_spec.cr
Normal file
|
@ -0,0 +1,19 @@
|
|||
require "../../../spec_helper"
|
||||
|
||||
module Ameba::Rule::Naming
|
||||
subject = Filename.new
|
||||
|
||||
describe Filename do
|
||||
it "passes if filename is correct" do
|
||||
expect_no_issues subject, code: "", path: "src/foo.cr"
|
||||
expect_no_issues subject, code: "", path: "src/foo_bar.cr"
|
||||
end
|
||||
|
||||
it "fails if filename is wrong" do
|
||||
expect_issue subject, <<-CRYSTAL, path: "src/fooBar.cr"
|
||||
|
||||
# ^{} error: Filename should be underscore-cased: foo_bar.cr, not fooBar.cr
|
||||
CRYSTAL
|
||||
end
|
||||
end
|
||||
end
|
28
src/ameba/rule/naming/filename.cr
Normal file
28
src/ameba/rule/naming/filename.cr
Normal file
|
@ -0,0 +1,28 @@
|
|||
module Ameba::Rule::Naming
|
||||
# A rule that enforces file names to be in underscored case.
|
||||
#
|
||||
# YAML configuration example:
|
||||
#
|
||||
# ```
|
||||
# Naming/Filename:
|
||||
# Enabled: true
|
||||
# ```
|
||||
class Filename < Base
|
||||
properties do
|
||||
description "Enforces file names to be in underscored case"
|
||||
end
|
||||
|
||||
MSG = "Filename should be underscore-cased: %s, not %s"
|
||||
|
||||
private LOCATION = {1, 1}
|
||||
|
||||
def test(source : Source)
|
||||
path = Path[source.path]
|
||||
name = path.basename
|
||||
|
||||
return if (expected = name.underscore) == name
|
||||
|
||||
issue_for LOCATION, MSG % {expected, name}
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue