grunt-import-clean
Advanced tools
Comparing version 0.1.8 to 0.1.9
@@ -13,3 +13,2 @@ /* | ||
grunt.initConfig({ | ||
@@ -42,8 +41,5 @@ | ||
} | ||
}); | ||
grunt.loadTasks( 'tasks' ); | ||
@@ -57,3 +53,2 @@ [ | ||
grunt.registerTask( 'default' , [ | ||
@@ -65,3 +60,2 @@ 'jshint', | ||
grunt.registerTask( 'test' , [ | ||
@@ -72,23 +66,2 @@ 'clean', | ||
]); | ||
}; | ||
{ | ||
"name": "grunt-import-clean", | ||
"description": "identify unused imports in es6 modules", | ||
"version": "0.1.8", | ||
"version": "0.1.9", | ||
"homepage": "https://github.com/elnarddogg/grunt-import-clean", | ||
@@ -6,0 +6,0 @@ "author": { |
module.exports = function( grunt ) { | ||
'use strict'; | ||
var util = require( 'util' ); | ||
var fs = require( 'fs-extra' ); | ||
@@ -30,5 +28,5 @@ var colors = require( 'colors' ); | ||
); | ||
}, []); | ||
},[]); | ||
util.print( | ||
process.stdout.write( | ||
'Validating imports in ' + | ||
@@ -62,3 +60,3 @@ files.length + ' files... ' | ||
msg = '\ntest output written to tmp/' + that.target + '.json'; | ||
util.puts( msg.yellow ); | ||
console.log( msg.yellow ); | ||
} | ||
@@ -76,3 +74,3 @@ else if (result.foundFiles) { | ||
if (options.force) { | ||
util.puts(( 'Warning: ' + msg ).yellow ); | ||
console.log(( 'Warning: ' + msg ).yellow ); | ||
} | ||
@@ -84,26 +82,6 @@ else { | ||
else { | ||
util.puts( '\u2713 OK'.green ); | ||
console.log( '\u2713 OK'.green ); | ||
} | ||
}); | ||
}; | ||
module.exports = (function() { | ||
'use strict'; | ||
// aggregate results | ||
var path = require( 'path' ); | ||
return function( files ) { | ||
var result = { | ||
@@ -31,6 +25,3 @@ unused: {}, | ||
return result; | ||
}; | ||
}()); | ||
}()); |
@@ -5,8 +5,3 @@ module.exports = (function() { | ||
// remove any commented code from input | ||
return function( input ) { | ||
var RE_COMMENT1 = /\/\/.*/gi; | ||
@@ -38,23 +33,2 @@ var RE_COMMENT2 = /\/\*.*\*\//gi; | ||
}; | ||
}()); | ||
@@ -5,8 +5,3 @@ module.exports = (function() { | ||
// extract imports for each file and return as an array | ||
return function( file ) { | ||
var RE_EXTRACT = /^(import(?:[^;]|\n)*from.*(?:'|"|;))$/gmi; | ||
@@ -25,15 +20,10 @@ var RE_START = /^import/i; | ||
if (text) { | ||
input = input.replace( RE_EXTRACT , '' ); | ||
text.forEach(function( line ) { | ||
if (RE_START.test( line )) { | ||
block = []; | ||
} | ||
if (Array.isArray( block )) { | ||
block.push( line ); | ||
} | ||
if (RE_END.test( line )) { | ||
@@ -43,3 +33,2 @@ imports.push( block ); | ||
} | ||
}); | ||
@@ -65,27 +54,4 @@ | ||
file.imports = imports; | ||
return file; | ||
}; | ||
}()); | ||
module.exports = (function() { | ||
'use strict'; | ||
return { | ||
@@ -14,3 +11,2 @@ shared: require( './shared' ), | ||
}; | ||
}()); | ||
}()); |
module.exports = (function() { | ||
'use strict'; | ||
// print output | ||
var colors = require( 'colors' ); | ||
function theme( text , name ) { | ||
@@ -24,30 +18,24 @@ text = text.toString(); | ||
return function( unused ) { | ||
var RE_FILES = /(".*")\:/i; | ||
var RE_IMPORTS = /(".*")\,?$/i; | ||
var str = JSON.stringify( unused , null , 2 ) | ||
.split( '\n' ) | ||
.map(function( line ) { | ||
var match; | ||
if (RE_FILES.test( line )) { | ||
match = RE_FILES.exec( line ); | ||
match = match ? match[1] : line; | ||
line = line.replace( RE_FILES , theme( match , 'files' ) + ':'); | ||
} | ||
else if (RE_IMPORTS.test( line )) { | ||
match = RE_IMPORTS.exec( line ); | ||
match = match ? (match[0].replace( match[1] , theme( match[1] , 'imports' ))) : line; | ||
line = line.replace( RE_IMPORTS , match ); | ||
} | ||
return line; | ||
}) | ||
.join( '\n' ); | ||
.split( '\n' ) | ||
.map(function( line ) { | ||
var match; | ||
if (RE_FILES.test( line )) { | ||
match = RE_FILES.exec( line ); | ||
match = match ? match[1] : line; | ||
line = line.replace( RE_FILES , theme( match , 'files' ) + ':'); | ||
} | ||
else if (RE_IMPORTS.test( line )) { | ||
match = RE_IMPORTS.exec( line ); | ||
match = match ? (match[0].replace( match[1] , theme( match[1] , 'imports' ))) : line; | ||
line = line.replace( RE_IMPORTS , match ); | ||
} | ||
return line; | ||
}) | ||
.join( '\n' ); | ||
console.log( '\n\n' + str + '\n' ); | ||
} | ||
}()); | ||
@@ -54,0 +42,0 @@ |
module.exports = (function() { | ||
'use strict'; | ||
var UNDEFINED; | ||
return { | ||
ensureArray: function( subject ) { | ||
return (Array.isArray( subject ) ? subject : ( subject !== UNDEFINED ? [ subject ] : [] )); | ||
return (Array.isArray( subject ) ? subject : ( subject !== undefined ? [ subject ] : [] )); | ||
}, | ||
escRegExp: function( str ) { | ||
return str.replace( /[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g , '\\$&' ); | ||
} | ||
}; | ||
}()); | ||
module.exports = (function() { | ||
'use strict'; | ||
// write test output | ||
var path = require( 'path' ); | ||
var fs = require( 'fs-extra' ); | ||
@@ -19,3 +13,2 @@ function Test( taskDir ) { | ||
Test.prototype = { | ||
@@ -29,6 +22,3 @@ write: function( target , output ) { | ||
return Test; | ||
}()); | ||
}()); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28514
965