-
Notifications
You must be signed in to change notification settings - Fork 1
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
0 parents
commit 8bdde61
Showing
20 changed files
with
672 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 4 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false | ||
|
||
[package.json] | ||
indent_size = 2 |
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,8 @@ | ||
{ | ||
"root": true, | ||
"extends": [ | ||
"./node_modules/@satazor/eslint-config/es6.js", | ||
"./node_modules/@satazor/eslint-config/addons/node.js", | ||
"./node_modules/@satazor/eslint-config/addons/node-v4-es6.js" | ||
] | ||
} |
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,4 @@ | ||
/node_modules | ||
/npm-debug.* | ||
/test/tmp | ||
/test/coverage |
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,5 @@ | ||
language: node_js | ||
node_js: | ||
- "4" | ||
- "5" | ||
script: "npm run test-travis" |
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,19 @@ | ||
Copyright (c) 2016 IndigoUnited | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is furnished | ||
to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
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,65 @@ | ||
# detect-repo-linters | ||
|
||
[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Coverage Status][coveralls-image]][coveralls-url] [![Dependency status][david-dm-image]][david-dm-url] [![Dev Dependency status][david-dm-dev-image]][david-dm-dev-url] | ||
|
||
[npm-url]:https://npmjs.org/package/detect-repo-linters | ||
[downloads-image]:http://img.shields.io/npm/dm/detect-repo-linters.svg | ||
[npm-image]:http://img.shields.io/npm/v/detect-repo-linters.svg | ||
[travis-url]:https://travis-ci.org/IndigoUnited/node-detect-repo-linters | ||
[travis-image]:http://img.shields.io/travis/IndigoUnited/node-detect-repo-linters.svg | ||
[coveralls-url]:https://coveralls.io/r/IndigoUnited/node-detect-repo-linters | ||
[coveralls-image]:https://img.shields.io/coveralls/IndigoUnited/node-detect-repo-linters.svg | ||
[david-dm-url]:https://david-dm.org/IndigoUnited/node-detect-repo-linters | ||
[david-dm-image]:https://img.shields.io/david/IndigoUnited/node-detect-repo-linters.svg | ||
[david-dm-dev-url]:https://david-dm.org/IndigoUnited/node-detect-repo-linters#info=devDependencies | ||
[david-dm-dev-image]:https://img.shields.io/david/dev/IndigoUnited/node-detect-repo-linters.svg | ||
|
||
Scans a repository directory, searching for configured linters. | ||
|
||
|
||
## Installation | ||
|
||
`$ npm install detect-repo-linters` | ||
|
||
|
||
## Usage | ||
|
||
`detectRepoLinters(repo, [callback]) -> Promise` | ||
|
||
You may consume the API using promises or callbacks, it's up to you. | ||
|
||
```js | ||
const detectRepoLinters = require('detect-repo-linters'); | ||
|
||
detectRepoLinters('repo-directory') | ||
.then((linters) => { | ||
console.log(linters); | ||
|
||
// { | ||
// general: ['editorconfig'], | ||
// js: ['eslint'], | ||
// css: ['stylelint'], | ||
// html: [], | ||
// } | ||
}); | ||
``` | ||
|
||
At the moment, `detect-repo-linters` can detect the following linters: | ||
|
||
- `general`: [editorconfig](http://editorconfig.org) | ||
- `js`: [eslint](http://eslint.org), [jscs](http://jscs.info) and [jshint](http://jshint.com) | ||
- `css`: [stylelint](http://stylelint.io) and [csslint](http://csslint.net) | ||
- `html`: [htmlhint](http://htmlhint.com) and [htmllint](http://htmllint.github.io) | ||
|
||
Feel free to a PR to include other linters as part of the detection! | ||
|
||
|
||
## Tests | ||
|
||
`$ npm test` | ||
`$ npm test-cov` to get coverage report | ||
|
||
|
||
## License | ||
|
||
Released under the [MIT License](http://www.opensource.org/licenses/mit-license.php). |
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,67 @@ | ||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
const requireDirectory = require('require-directory'); | ||
const callMeMaybe = require('call-me-maybe'); | ||
const detectors = requireDirectory(module, './lib', { recurse: false }); | ||
|
||
const linters = { | ||
general: [ | ||
{ name: 'editorconfig', fn: detectors.editorconfig }, | ||
], | ||
js: [ | ||
{ name: 'eslint', fn: detectors.eslint }, | ||
{ name: 'jscs', fn: detectors.jscs }, | ||
{ name: 'jshint', fn: detectors.jshint }, | ||
], | ||
css: [ | ||
{ name: 'stylelint', fn: detectors.stylelint }, | ||
{ name: 'csslint', fn: detectors.csslint }, | ||
], | ||
html: [ | ||
{ name: 'htmlhint', fn: detectors.htmlhint }, | ||
{ name: 'htmllint', fn: detectors.htmllint }, | ||
], | ||
}; | ||
|
||
function detectLinters(dir, linters) { | ||
return Promise.all(linters.map((linter) => linter.fn(dir))) | ||
.then((results) => { | ||
return linters | ||
.filter((linter, index) => results[index]) | ||
.map((linter) => linter.name); | ||
}); | ||
} | ||
|
||
function detectRepoLinters(dir, callback) { | ||
// Check if dir exists | ||
const promise = new Promise((resolve, reject) => { | ||
fs.stat(dir, (err) => { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(); | ||
} | ||
}); | ||
}) | ||
// Run the linter detectors and build the results | ||
.then(() => { | ||
const types = Object.keys(linters); | ||
const promises = types.map((type) => detectLinters(dir, linters[type])); | ||
|
||
return Promise.all(promises) | ||
.then((results) => { | ||
const ret = {}; | ||
|
||
results.forEach((result, index) => { | ||
ret[types[index]] = result; | ||
}); | ||
|
||
return ret; | ||
}); | ||
}); | ||
|
||
return callMeMaybe(callback, promise); | ||
} | ||
|
||
module.exports = detectRepoLinters; |
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,13 @@ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
const tryFiles = require('./util/tryFiles'); | ||
|
||
function detectCssLint(dir) { | ||
const paths = ['.csslintrc'] | ||
.map((entry) => path.join(dir, entry)); | ||
|
||
return tryFiles(paths); | ||
} | ||
|
||
module.exports = detectCssLint; |
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,12 @@ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
const tryFiles = require('./util/tryFiles'); | ||
|
||
function detectEditorConfig(dir) { | ||
const paths = ['.editorconfig'].map((entry) => path.join(dir, entry)); | ||
|
||
return tryFiles(paths); | ||
} | ||
|
||
module.exports = detectEditorConfig; |
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,18 @@ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
const tryFiles = require('./util/tryFiles'); | ||
const tryPackageJson = require('./util/tryPackageJson'); | ||
|
||
function detectEslint(dir) { | ||
const paths = ['.eslintrc.js', '.eslintrc.yaml', '.eslintrc.yml', '.eslintrc.json', '.eslintrc'] | ||
.map((entry) => path.join(dir, entry)); | ||
|
||
return Promise.all([ | ||
tryFiles(paths), | ||
tryPackageJson(dir, 'eslintConfig'), | ||
]) | ||
.then((booleans) => booleans.some((bool) => bool)); | ||
} | ||
|
||
module.exports = detectEslint; |
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,13 @@ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
const tryFiles = require('./util/tryFiles'); | ||
|
||
function detectHtmlHint(dir) { | ||
const paths = ['.htmlhintrc'] | ||
.map((entry) => path.join(dir, entry)); | ||
|
||
return tryFiles(paths); | ||
} | ||
|
||
module.exports = detectHtmlHint; |
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,13 @@ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
const tryFiles = require('./util/tryFiles'); | ||
|
||
function detectHtmlHint(dir) { | ||
const paths = ['.htmllintrc'] | ||
.map((entry) => path.join(dir, entry)); | ||
|
||
return tryFiles(paths); | ||
} | ||
|
||
module.exports = detectHtmlHint; |
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,18 @@ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
const tryFiles = require('./util/tryFiles'); | ||
const tryPackageJson = require('./util/tryPackageJson'); | ||
|
||
function detectJscs(dir) { | ||
const paths = ['.jscsrc', '.jscs.json'] | ||
.map((entry) => path.join(dir, entry)); | ||
|
||
return Promise.all([ | ||
tryFiles(paths), | ||
tryPackageJson(dir, 'jscsConfig'), | ||
]) | ||
.then((booleans) => booleans.some((bool) => bool)); | ||
} | ||
|
||
module.exports = detectJscs; |
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,18 @@ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
const tryFiles = require('./util/tryFiles'); | ||
const tryPackageJson = require('./util/tryPackageJson'); | ||
|
||
function detectJsHint(dir) { | ||
const paths = ['.jshintrc'] | ||
.map((entry) => path.join(dir, entry)); | ||
|
||
return Promise.all([ | ||
tryFiles(paths), | ||
tryPackageJson(dir, 'jshintConfig'), | ||
]) | ||
.then((booleans) => booleans.some((bool) => bool)); | ||
} | ||
|
||
module.exports = detectJsHint; |
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,18 @@ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
const tryFiles = require('./util/tryFiles'); | ||
const tryPackageJson = require('./util/tryPackageJson'); | ||
|
||
function detectStyleLint(dir) { | ||
const paths = ['.stylelintrc.js', '.stylelintrc.yaml', '.stylelintrc.json', '.stylelintrc'] | ||
.map((entry) => path.join(dir, entry)); | ||
|
||
return Promise.all([ | ||
tryFiles(paths), | ||
tryPackageJson(dir, 'stylelint'), | ||
]) | ||
.then((booleans) => booleans.some((bool) => bool)); | ||
} | ||
|
||
module.exports = detectStyleLint; |
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,30 @@ | ||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
|
||
function isFile(path) { | ||
return new Promise((resolve, reject) => { | ||
fs.stat(path, (err, stats) => { | ||
if (!err) { | ||
return resolve(stats.isFile()); | ||
} | ||
|
||
if (err.code === 'ENOENT') { | ||
return resolve(false); | ||
} | ||
|
||
reject(err); | ||
}); | ||
}); | ||
} | ||
|
||
function tryFiles(paths) { | ||
return Promise.all(paths.map((path) => isFile(path))) | ||
.then((results) => { | ||
const filteredResults = results.filter((exists) => exists); | ||
|
||
return !!filteredResults[0]; | ||
}); | ||
} | ||
|
||
module.exports = tryFiles; |
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,17 @@ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
const loadJsonFile = require('load-json-file'); | ||
|
||
function tryPackageJson(dir, prop) { | ||
return loadJsonFile(path.join(dir, 'package.json')) | ||
.then((json) => !!json[prop], (err) => { | ||
if (err.code === 'ENOENT') { | ||
return false; | ||
} | ||
|
||
throw err; | ||
}); | ||
} | ||
|
||
module.exports = tryPackageJson; |
Oops, something went wrong.