From 0e99444bb1a2e3451cfbd9530c56beef3fd8e5e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Estev=C3=A3o=20Soares=20dos=20Santos?= Date: Mon, 19 Jan 2015 15:43:47 +0000 Subject: [PATCH] feat(grunt-jscs): add grunt task jscs lint Now it's possible to enforce code style linting with jscs automatically when testing or building with grunt --- .jscs.json | 1 + Gruntfile.js | 131 ++++++++++++++++++++++++++++++--------------------- package.json | 1 + 3 files changed, 79 insertions(+), 54 deletions(-) diff --git a/.jscs.json b/.jscs.json index 9d0b1cf..f3d0acb 100644 --- a/.jscs.json +++ b/.jscs.json @@ -1,4 +1,5 @@ { + "validateIndentation": 2, "requireCurlyBraces": [ "if", "else", diff --git a/Gruntfile.js b/Gruntfile.js index 9de8c27..850f386 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -4,62 +4,85 @@ module.exports = function (grunt) { - // Project configuration. - grunt.initConfig({ - pkg: grunt.file.readJSON('package.json'), - concat: { - options: { - sourceMap: true, - banner: ";/*! <%= pkg.name %> <%= grunt.template.today('dd-mm-yyyy') %> */\n(function(){\n", - footer: "}).call(this)" - }, - dist: { - src: ['src/showdown.js', 'src/helpers.js', 'src/subParsers/*.js', 'src/loader.js'], - dest: 'dist/<%= pkg.name %>.js' - } - }, - uglify: { - options: { - sourceMap: true, - banner: '/*! <%= pkg.name %> <%= grunt.template.today("dd-mm-yyyy") %> */\n' - }, - dist: { - files: { - 'dist/<%= pkg.name %>.min.js': ['<%= concat.dist.dest %>'] - } - } - }, - jshint: { - files: ['Gruntfile.js', 'src/**/*.js'] - }, - simplemocha: { - node: { - src: 'test/node/**/*.js', - options: { - globals: ['should'], - timeout: 3000, - ignoreLeaks: false, - reporter: 'spec' - } - }, - browser: { - src: 'test/browser/**/*.js', - options: { - reporter: 'spec' - } - } + // Project configuration. + var config = { + pkg: grunt.file.readJSON('package.json'), + concat: { + options: { + sourceMap: true, + banner: ';/*! <%= pkg.name %> <%= grunt.template.today("dd-mm-yyyy") %> */\n(function(){\n', + footer: '}).call(this)' + }, + dist: { + src: [ + 'src/showdown.js', + 'src/helpers.js', + 'src/subParsers/*.js', + 'src/loader.js' + ], + dest: 'dist/<%= pkg.name %>.js' + } + }, + uglify: { + options: { + sourceMap: true, + banner: '/*! <%= pkg.name %> <%= grunt.template.today("dd-mm-yyyy") %> */\n' + }, + dist: { + files: { + 'dist/<%= pkg.name %>.min.js': ['<%= concat.dist.dest %>'] } - }); + } + }, + jshint: { + files: [ + 'Gruntfile.js', + 'src/**/*.js', + 'test/**/*.js' + ] + }, + jscs: { + options: { + config: '.jscs.json', + files: [ + 'Gruntfile.js', + 'src/**/*.js', + 'test/**/*.js' + ] + } + }, + simplemocha: { + node: { + src: 'test/node/**/*.js', + options: { + globals: ['should'], + timeout: 3000, + ignoreLeaks: false, + reporter: 'spec' + } + }, + browser: { + src: 'test/browser/**/*.js', + options: { + reporter: 'spec' + } + } + } + }; - grunt.loadNpmTasks('grunt-contrib-concat'); - grunt.loadNpmTasks('grunt-contrib-uglify'); - grunt.loadNpmTasks('grunt-contrib-jshint'); - grunt.loadNpmTasks('grunt-simple-mocha'); + grunt.initConfig(config); - grunt.registerTask('test', ['jshint', 'concat', 'simplemocha']); - grunt.registerTask('test-without-building', ['simplemocha']); - grunt.registerTask('build', ['jshint', 'concat', 'test', 'uglify']); + grunt.loadNpmTasks('grunt-contrib-concat'); + grunt.loadNpmTasks('grunt-contrib-uglify'); + grunt.loadNpmTasks('grunt-contrib-jshint'); + grunt.loadNpmTasks('grunt-simple-mocha'); + grunt.loadNpmTasks('grunt-jscs'); - // Default task(s). - grunt.registerTask('default', []); + grunt.registerTask('lint', ['jshint', 'jscs']); + grunt.registerTask('test', ['lint', 'concat', 'simplemocha']); + grunt.registerTask('test-without-building', ['simplemocha']); + grunt.registerTask('build', ['lint', 'test', 'uglify']); + + // Default task(s). + grunt.registerTask('default', []); }; diff --git a/package.json b/package.json index 70d9e57..eacf65b 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ "grunt-contrib-concat": "^0.5.0", "grunt-contrib-jshint": "^0.10.0", "grunt-contrib-uglify": "^0.6.0", + "grunt-jscs": "^1.2.0", "grunt-simple-mocha": "^0.4.0", "jscs": "^1.10.0", "mocha": "*",