From e2d6c690394653e36d50431c546c261b06cda8da Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Sat, 9 Mar 2024 22:37:58 +0100 Subject: [PATCH 1/3] Include `SpecFilename` rule properties in its documentation --- src/ameba/rule/lint/spec_filename.cr | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ameba/rule/lint/spec_filename.cr b/src/ameba/rule/lint/spec_filename.cr index 9711806f7..87f9274a8 100644 --- a/src/ameba/rule/lint/spec_filename.cr +++ b/src/ameba/rule/lint/spec_filename.cr @@ -8,6 +8,8 @@ module Ameba::Rule::Lint # ``` # Lint/SpecFilename: # Enabled: true + # IgnoredDirs: [spec/support spec/fixtures spec/data] + # IgnoredFilenames: [spec_helper] # ``` class SpecFilename < Base properties do From a2c9aa67ccd498e34ccae430621f87971e2fc1d7 Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Sat, 9 Mar 2024 22:38:23 +0100 Subject: [PATCH 2/3] Add missed spec case for files outside `spec/` folder --- spec/ameba/rule/lint/spec_filename_spec.cr | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/spec/ameba/rule/lint/spec_filename_spec.cr b/spec/ameba/rule/lint/spec_filename_spec.cr index 44d51dc8e..8ef8bfe77 100644 --- a/spec/ameba/rule/lint/spec_filename_spec.cr +++ b/spec/ameba/rule/lint/spec_filename_spec.cr @@ -4,6 +4,11 @@ module Ameba::Rule::Lint subject = SpecFilename.new describe SpecFilename do + it "passes if relative file path does not start with `spec/`" do + expect_no_issues subject, code: "", path: "src/spec/foo.cr" + expect_no_issues subject, code: "", path: "src/spec/foo/bar.cr" + end + it "passes if filename is correct" do expect_no_issues subject, code: "", path: "spec/foo_spec.cr" expect_no_issues subject, code: "", path: "spec/foo/bar_spec.cr" From a661cf10fc408e2c5b63e2db86e2dbea769645f4 Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Sat, 9 Mar 2024 22:38:47 +0100 Subject: [PATCH 3/3] Ignore files with extensions other than `.cr` --- spec/ameba/rule/lint/spec_filename_spec.cr | 5 +++++ src/ameba/rule/lint/spec_filename.cr | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/spec/ameba/rule/lint/spec_filename_spec.cr b/spec/ameba/rule/lint/spec_filename_spec.cr index 8ef8bfe77..30a2c57de 100644 --- a/spec/ameba/rule/lint/spec_filename_spec.cr +++ b/spec/ameba/rule/lint/spec_filename_spec.cr @@ -9,6 +9,11 @@ module Ameba::Rule::Lint expect_no_issues subject, code: "", path: "src/spec/foo/bar.cr" end + it "passes if file extension is not `.cr`" do + expect_no_issues subject, code: "", path: "spec/foo.json" + expect_no_issues subject, code: "", path: "spec/foo/bar.json" + end + it "passes if filename is correct" do expect_no_issues subject, code: "", path: "spec/foo_spec.cr" expect_no_issues subject, code: "", path: "spec/foo/bar_spec.cr" diff --git a/src/ameba/rule/lint/spec_filename.cr b/src/ameba/rule/lint/spec_filename.cr index 87f9274a8..32492a6fa 100644 --- a/src/ameba/rule/lint/spec_filename.cr +++ b/src/ameba/rule/lint/spec_filename.cr @@ -28,8 +28,10 @@ module Ameba::Rule::Lint name = path_.stem path = path_.to_s - # check files only within spec/ directory + # check only files within spec/ directory return unless path.starts_with?("spec/") + # check only files with `.cr` extension + return unless path.ends_with?(".cr") # ignore files having `_spec` suffix return if name.ends_with?("_spec")