Skip to content

Commit

Permalink
Handle case where step_definitions does not exist, refactor and add c…
Browse files Browse the repository at this point in the history
…offee script lint file
  • Loading branch information
tomkadwill committed Mar 13, 2016
1 parent 80c682d commit c003241
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 15 deletions.
6 changes: 6 additions & 0 deletions coffeelint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"max_line_length" : {
"level" : "error",
"value" : 120
}
}
41 changes: 26 additions & 15 deletions lib/provider.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,32 @@ module.exports =
return [] unless @matchCucumberKeyword(line)
results = []

stats = fs.lstatSync("#{@rootDirectory()}#{@featuresDirectory()}/step_definitions");
if stats.isDirectory()
#TODO: first search step definitions for your file
for step_def_file in fs.readdirSync("#{@rootDirectory()}#{@featuresDirectory()}/step_definitions")
data = fs.readFileSync "#{@rootDirectory()}#{@featuresDirectory()}/step_definitions/#{step_def_file}", 'utf8'
while (myRegexArray = CUCUMBER_STEP_DEF_PATTERN.exec(data)) != null
results.push({"snippet":@replacedCucumberRegex(myRegexArray[2])})
else
@featureDirError() unless fs.lstatSync("#{@rootDirectory()}#{@featuresDirectory()}").isDirectory()

for feature in fs.readdirSync("#{@rootDirectory()}#{@featuresDirectory()}")
continue unless /.feature/.test(feature)
data = fs.readFileSync "#{@rootDirectory()}#{@featuresDirectory()}/#{feature}", 'utf8'
while (myRegexArray = CUCUMBER_KEYWORDS_PATTERN.exec(data)) != null
results.push({"text":myRegexArray[2].replace /^\s+|\s+$/g, ""})
try
stats = fs.lstatSync("#{@rootDirectory()}#{@featuresDirectory()}/step_definitions")
if stats.isDirectory()
return @scanStepDefinitionsDir(results)
else
return @scanFeaturesDir(results)
catch error
return @scanFeaturesDir(results)

scanStepDefinitionsDir: (results) ->
#TODO: first search step definitions for your file
for step_def_file in fs.readdirSync("#{@rootDirectory()}#{@featuresDirectory()}/step_definitions")
data = fs.readFileSync "#{@rootDirectory()}#{@featuresDirectory()}/step_definitions/#{step_def_file}", 'utf8'
while (myRegexArray = CUCUMBER_STEP_DEF_PATTERN.exec(data)) != null
results.push({"snippet":@replacedCucumberRegex(myRegexArray[2])})

return results

scanFeaturesDir: (results) ->
@featureDirError() unless fs.lstatSync("#{@rootDirectory()}#{@featuresDirectory()}").isDirectory()

for feature in fs.readdirSync("#{@rootDirectory()}#{@featuresDirectory()}")
continue unless /.feature/.test(feature)
data = fs.readFileSync "#{@rootDirectory()}#{@featuresDirectory()}/#{feature}", 'utf8'
while (myRegexArray = CUCUMBER_KEYWORDS_PATTERN.exec(data)) != null
results.push({"text":myRegexArray[2].replace /^\s+|\s+$/g, ""})

return results

Expand Down

0 comments on commit c003241

Please sign in to comment.