-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(index): add literate: 'auto', make it default
Add new literate option value - 'auto': - treat .litcoffee and .coffee.md files as literate CoffeeScript - assume everything else is CoffeeScript This change simplifies gulp setup for projects with mixed .coffee and .litcoffee files. Add tests for it in test/literate-detection.coffee. Update readme.md accordingly. BREAKING CHANGE: literate default value changes from false to 'auto'. If you somewhy lint .litcoffee or .coffee.md files as CoffeeScript this may change linting results. To fix this explicitly set literate to false.
- Loading branch information
Showing
3 changed files
with
255 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,238 @@ | ||
# module dependencies | ||
should = require 'should' | ||
gutil = require 'gulp-util' | ||
path = require 'path' | ||
|
||
# SUT | ||
coffeelint = require '../' | ||
|
||
# These tests are in separate file for readability. | ||
# Also coffeelint says cyclomatic complexity is too high when these tests | ||
# are merged with test/main.coffee. | ||
describe 'gulp-coffeelint', -> | ||
describe 'coffeelint()', -> | ||
describe 'CoffeeScript and Literate CoffeeScript detection', -> | ||
describe 'should detect CoffeeScript', -> | ||
it '... on .coffee with Literate contents', (done) -> | ||
dataCounter = 0 | ||
|
||
fakeFile = new gutil.File | ||
path: './test/fixture/file.coffee', | ||
cwd: './test/', | ||
base: './test/fixture/', | ||
contents: new Buffer 'Comments!\n yeah()' | ||
|
||
stream = coffeelint {} | ||
|
||
stream.on 'data', (newFile) -> | ||
++dataCounter | ||
should.exist(newFile.coffeelint.success) | ||
should.exist(newFile.coffeelint.literate) | ||
newFile.coffeelint.success.should.be.false | ||
newFile.coffeelint.literate.should.be.false | ||
|
||
stream.once 'end', -> | ||
dataCounter.should.equal 1 | ||
done() | ||
|
||
stream.write fakeFile | ||
stream.end() | ||
|
||
it '... on .litcoffee with literate: false', (done) -> | ||
dataCounter = 0 | ||
|
||
fakeFile = new gutil.File | ||
path: './test/fixture/file.litcoffee', | ||
cwd: './test/', | ||
base: './test/fixture/', | ||
contents: new Buffer 'Comments!\n yeah()' | ||
|
||
stream = coffeelint {}, false | ||
|
||
stream.on 'data', (newFile) -> | ||
++dataCounter | ||
should.exist(newFile.coffeelint.success) | ||
should.exist(newFile.coffeelint.literate) | ||
newFile.coffeelint.success.should.be.false | ||
newFile.coffeelint.literate.should.be.false | ||
|
||
stream.once 'end', -> | ||
dataCounter.should.equal 1 | ||
done() | ||
|
||
stream.write fakeFile | ||
stream.end() | ||
|
||
for extension in ['.coffee', '.js', '.custom', '.md', '.', ''] | ||
((extension) -> | ||
it '... on ' + (extension || 'no extension'), (done) -> | ||
dataCounter = 0 | ||
|
||
fakeFile = new gutil.File | ||
path: './test/fixture/file' + extension, | ||
cwd: './test/', | ||
base: './test/fixture/', | ||
contents: new Buffer 'yeah()' | ||
|
||
stream = coffeelint {} | ||
|
||
stream.on 'data', (newFile) -> | ||
++dataCounter | ||
should.exist(newFile.coffeelint.success) | ||
should.exist(newFile.coffeelint.literate) | ||
newFile.coffeelint.success.should.be.true | ||
newFile.coffeelint.literate.should.be.false | ||
|
||
stream.once 'end', -> | ||
dataCounter.should.equal 1 | ||
done() | ||
|
||
stream.write fakeFile | ||
stream.end() | ||
)(extension) | ||
|
||
describe 'should detect Literate CoffeeScript', -> | ||
for extension in [ ".litcoffee", ".coffee.md" ] | ||
((extension) -> | ||
it '... on ' + extension, (done) -> | ||
dataCounter = 0 | ||
|
||
fakeFile = new gutil.File | ||
path: './test/fixture/file' + extension, | ||
cwd: './test/', | ||
base: './test/fixture/', | ||
contents: new Buffer 'Comments!\n yeah()' | ||
|
||
stream = coffeelint {} | ||
|
||
stream.on 'data', (newFile) -> | ||
++dataCounter | ||
should.exist(newFile.coffeelint.success) | ||
should.exist(newFile.coffeelint.literate) | ||
newFile.coffeelint.success.should.be.true | ||
newFile.coffeelint.literate.should.be.true | ||
|
||
stream.once 'end', -> | ||
dataCounter.should.equal 1 | ||
done() | ||
|
||
stream.write fakeFile | ||
stream.end() | ||
)(extension) | ||
|
||
it '... on .coffee with literate: true', (done) -> | ||
dataCounter = 0 | ||
|
||
fakeFile = new gutil.File | ||
path: './test/fixture/file.coffee', | ||
cwd: './test/', | ||
base: './test/fixture/', | ||
contents: new Buffer 'yeah()' | ||
|
||
stream = coffeelint {}, true | ||
|
||
stream.on 'data', (newFile) -> | ||
++dataCounter | ||
should.exist(newFile.coffeelint.success) | ||
should.exist(newFile.coffeelint.literate) | ||
newFile.coffeelint.success.should.be.true | ||
newFile.coffeelint.literate.should.be.true | ||
|
||
stream.once 'end', -> | ||
dataCounter.should.equal 1 | ||
done() | ||
|
||
stream.write fakeFile | ||
stream.end() | ||
|
||
describe 'multiple files', -> | ||
it 'should detect CS and LCS in single stream', (done) -> | ||
dataCounter = 0 | ||
|
||
extensions = | ||
'.coffee': false, | ||
'.litcoffee': true, | ||
'.js': false, | ||
'.coffee.md': true, | ||
'.md': false | ||
|
||
fakeFiles = for extension, literate of extensions | ||
fakeFile = new gutil.File | ||
path: './test/fixture/file' + extension, | ||
cwd: './test/', | ||
base: './test/fixture/', | ||
contents: new Buffer 'yeah()' | ||
fakeFile.literate = literate | ||
fakeFile | ||
|
||
stream = coffeelint {} | ||
|
||
stream.on 'data', (newFile) -> | ||
should.exist(newFile.coffeelint.success) | ||
should.exist(newFile.coffeelint.literate) | ||
newFile.coffeelint.literate.should.equal( | ||
newFile.literate) | ||
++dataCounter | ||
|
||
stream.once 'end', -> | ||
dataCounter.should.equal 5 | ||
done() | ||
|
||
stream.write fakeFile for fakeFile in fakeFiles | ||
stream.end() | ||
|
||
it 'should treat all as LCS when literate: true', (done) -> | ||
dataCounter = 0 | ||
|
||
extensions = ['.coffee', '.litcoffee', '.js', | ||
'.coffee.md', '.md'] | ||
|
||
fakeFiles = for extension in extensions | ||
fakeFile = new gutil.File | ||
path: './test/fixture/file' + extension, | ||
cwd: './test/', | ||
base: './test/fixture/', | ||
contents: new Buffer 'yeah()' | ||
|
||
stream = coffeelint {}, true | ||
|
||
stream.on 'data', (newFile) -> | ||
should.exist(newFile.coffeelint.success) | ||
should.exist(newFile.coffeelint.literate) | ||
newFile.coffeelint.literate.should.be.true | ||
++dataCounter | ||
|
||
stream.once 'end', -> | ||
dataCounter.should.equal 5 | ||
done() | ||
|
||
stream.write fakeFile for fakeFile in fakeFiles | ||
stream.end() | ||
|
||
it 'should treat all as CS when literate: false', (done) -> | ||
dataCounter = 0 | ||
|
||
extensions = ['.coffee', '.litcoffee', '.js', | ||
'.coffee.md', '.md'] | ||
|
||
fakeFiles = for extension in extensions | ||
fakeFile = new gutil.File | ||
path: './test/fixture/file' + extension, | ||
cwd: './test/', | ||
base: './test/fixture/', | ||
contents: new Buffer 'yeah()' | ||
|
||
stream = coffeelint {}, false | ||
|
||
stream.on 'data', (newFile) -> | ||
should.exist(newFile.coffeelint.success) | ||
should.exist(newFile.coffeelint.literate) | ||
newFile.coffeelint.literate.should.be.false | ||
++dataCounter | ||
|
||
stream.once 'end', -> | ||
dataCounter.should.equal 5 | ||
done() | ||
|
||
stream.write fakeFile for fakeFile in fakeFiles | ||
stream.end() |