forked from SimenB/stylint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
77 lines (69 loc) · 2.11 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
'use strict'
// our stampit modules
var stampit = require( 'stampit' )
var fs = require( 'fs' )
// let there be light ( * )
// basically, with stampit we take a bunch of different objects
// and methods and compose them into one mega object, the app
// appropriately namespaced, with methods on the prototype,
// and `this` set consistently (ie, available throughout the app)
//
// basic app flow below
// init() -> read() -> parse() -> lint() -> done()
// init() -> watch() -> read() -> parse() -> lint() -> done()
/**
* main stylint kickoff function
* @param {string} path [custom path if used programmatically]
* @param {object} config [config if used programmatically]
* @param {function} [callback] [a callback called just before exiting the process if not watching]
* @return {Object} [the composed stylint object]
*/
var Stylint = function( path, config, callback ) {
return stampit().compose(
require( './src/core/' ),
require( './src/checks/' ),
require( './src/state/' ),
stampit().enclose( function() {
var pkg = null
try {
pkg = require( process.cwd() + '/package.json' )
}
catch ( err ) {
// no output
}
// set safe path defaults
if ( typeof path === 'undefined' ) {
this.state.path = './'
}
else if ( path instanceof Array || typeof path === 'string' ) {
this.state.path = path
}
// look for a stylintignore array
// for ignoring specific files
// first look in package.json
// then look for .stylintignore in the main dir
if ( pkg !== null &&
typeof pkg.stylintignore !== 'undefined' &&
pkg.stylintignore instanceof Array ) {
this.state.exclude = pkg.stylintignore
}
else {
try {
var stylintIgnore = fs.readFileSync( process.cwd() + '/.stylintignore' )
this.state.exclude = stylintIgnore
.toString()
.split( '\n' )
.filter( function( d ) {
return d
} )
}
catch ( err ) {
// do no-thing
}
}
this.customConfig = typeof config === 'object' ? config : false
this.callback = callback || function() {}
} ).enclose( require( './src/core/init' ) )
)
}
module.exports = Stylint