Skip to content

Commit

Permalink
First commit - adding files
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenmathieson committed Sep 24, 2012
1 parent 02d675e commit d6276a6
Show file tree
Hide file tree
Showing 7 changed files with 6,631 additions and 3 deletions.
22 changes: 22 additions & 0 deletions LICENSE-MIT
@@ -0,0 +1,22 @@
Copyright (c) 2012 Stephen Mathieson

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.
30 changes: 27 additions & 3 deletions README.md
@@ -1,4 +1,28 @@
grunt-jslint
============
# grunt-jslint

A Grunt task for running JSLint
Validates JavaScript files with JSLint

## Getting Started
Install this grunt plugin next to your project's [grunt.js gruntfile][getting_started] with: `npm install grunt-jslint`

Then add this line to your project's `grunt.js` gruntfile:

```javascript
grunt.loadNpmTasks('grunt-jslint');
```

[grunt]: https://github.com/cowboy/grunt
[getting_started]: https://github.com/cowboy/grunt/blob/master/docs/getting_started.md

## Documentation
_(Coming soon)_

## Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [grunt][grunt].

## Release History
_(Nothing yet)_

## License
Copyright (c) 2012 Stephen Mathieson
Licensed under the MIT license.
2 changes: 2 additions & 0 deletions bin/grunt-jslint
@@ -0,0 +1,2 @@
#!/usr/bin/env node
require('grunt').npmTasks('grunt-jslint').cli();
28 changes: 28 additions & 0 deletions grunt.js
@@ -0,0 +1,28 @@
/*jslint node:true*/
module.exports = function (grunt) {
'use strict';

// Project configuration.
grunt.initConfig({
watch: {
files: '<config:jslint.files>',
tasks: 'default'
},
jslint: {
files: [ // some example files
'grunt.js', 'tasks/**/*.js'
]
},
jslint_options: { // some example JSLint directives
browser: true,
vars: false
}
});

// Load local tasks.
grunt.loadTasks('tasks');

// Default task.
grunt.registerTask('default', 'jslint');

};
40 changes: 40 additions & 0 deletions package.json
@@ -0,0 +1,40 @@
{
"name": "grunt-jslint",
"description": "Validates JavaScript files with JSLint",
"version": "0.1.0",
"homepage": "https://github.com/stephenmathieson/grunt-jslint",
"author": {
"name": "Stephen Mathieson",
"email": "me@stephenmathieson.com"
},
"repository": {
"type": "git",
"url": "git://github.com/stephenmathieson/grunt-jslint.git"
},
"bugs": {
"url": "https://github.com/stephenmathieson/grunt-jslint/issues"
},
"licenses": [
{
"type": "MIT",
"url": "https://github.com/stephenmathieson/grunt-jslint/blob/master/LICENSE-MIT"
}
],
"main": "grunt.js",
"bin": "bin/grunt-jslint",
"engines": {
"node": "*"
},
"scripts": {
"test": "grunt test"
},
"dependencies": {
"grunt": "~0.3.11"
},
"devDependencies": {
"grunt": "~0.3.11"
},
"keywords": [
"gruntplugin"
]
}
59 changes: 59 additions & 0 deletions tasks/jslint.js
@@ -0,0 +1,59 @@
/*!
* grunt-jslint
* https://github.com/stephenmathieson/grunt-jslint
*
* Copyright (c) 2012 Stephen Mathieson
* Licensed under the MIT license.
*/

/*jslint node:true*/
/*jslint stupid:true*/
/*jslint nomen:true*/

module.exports = function (grunt) {
'use strict';

var jslint,
vm = require('vm'),
fs = require('fs'),
ctx = vm.createContext();

vm.runInContext(fs.readFileSync(__dirname + '/lib/jslint.js'), ctx);

jslint = ctx.JSLINT;

grunt.registerMultiTask('jslint', 'Validates JavaScript files with JSLint', function () {

var options = grunt.config('jslint_options') || {},
files = grunt.file.expandFiles(this.file.src),
fileCount = files.length;

files.forEach(function (filepath) {
var source = grunt.file.read(filepath);

if (!jslint(source, options)) {

grunt.log.writeln(jslint.errors.length.toString().red + ' JSLint violations in `' + filepath.yellow + '`');

jslint.errors.forEach(function (lintError) {

if (lintError !== null) {
var message = 'Error on line ' + (lintError.line || 'unknown').toString();
message += ', character ' + (lintError.character || '').toString();
message += ': ' + (lintError.reason || '').red;

grunt.log.error(message);
}
});

}

});

if (this.errorCount) {
grunt.log.writeln(this.errorCount.toString().red + ' JSLint violations in ' + fileCount.toString().yellow + ' files');
return false;
}
});

};

0 comments on commit d6276a6

Please sign in to comment.