Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
477 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module CukeLinter | ||
|
||
# A generic linter that can be used to make arbitrary linting rules | ||
|
||
class Linter | ||
|
||
# Creates a new linter object | ||
def initialize(name: nil, message: nil, rule: nil) | ||
@name = name || self.class.name.split('::').last | ||
@message = message || "#{self.name} problem detected" | ||
@rule = rule | ||
end | ||
|
||
# Returns the name of the linter | ||
def name | ||
@name | ||
end | ||
|
||
# Lints the given model and returns linting data about said model | ||
def lint(model) | ||
raise 'No linting rule provided!' unless @rule || respond_to?(:rule) | ||
|
||
problem_found = respond_to?(:rule) ? rule(model) : @rule.call(model) | ||
|
||
if problem_found | ||
problem_message = respond_to?(:message) ? message : @message | ||
|
||
{ problem: problem_message, location: "#{model.get_ancestor(:feature_file).path}:#{model.source_line}" } | ||
else | ||
nil | ||
end | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module CukeLinter | ||
# The release version of this gem | ||
VERSION = "0.3.1" | ||
VERSION = "0.4.0" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
Feature: Custom linters | ||
|
||
In addition to the linters provided by CukeSlicer, custom linters can be used. A linter is essentially any object that provides a few needed methods. In order to simplify the creation of custom linters, a base linter class is available that provides these needed methods. | ||
|
||
|
||
Scenario: Creating a custom linter object | ||
Given the following custom linter object: | ||
""" | ||
custom_name = 'MyCustomLinter' | ||
custom_message = 'My custom message' | ||
custom_rule = lambda do |model| | ||
# Your logic here, return true for a problem and false for not problem | ||
true | ||
end | ||
@linter = CukeLinter::Linter.new(name: custom_name, | ||
message: custom_message, | ||
rule: custom_rule) | ||
""" | ||
And a model to lint | ||
When the model is linted | ||
Then an error is reported | ||
| linter | problem | location | | ||
| MyCustomLinter | My custom message | <path_to_file>:<model_line_number> | | ||
|
||
Scenario: Creating a custom linter class | ||
Given the following custom linter class: | ||
""" | ||
class MyCustomLinter < CukeLinter::Linter | ||
def name | ||
'MyCustomLinter' | ||
end | ||
def message | ||
'My custom message' | ||
end | ||
def rule(model) | ||
# Your logic here, return true for a problem and false for not problem | ||
true | ||
end | ||
end | ||
""" | ||
And the following code is used: | ||
""" | ||
@linter = MyCustomLinter.new | ||
""" | ||
And a model to lint | ||
When the model is linted | ||
Then an error is reported | ||
| linter | problem | location | | ||
| MyCustomLinter | My custom message | <path_to_file>:<model_line_number> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.