diff --git a/build/Gruntfile.coffee b/build/Gruntfile.coffee index cae4d02c9..615800a63 100644 --- a/build/Gruntfile.coffee +++ b/build/Gruntfile.coffee @@ -1,7 +1,6 @@ fs = require 'fs' path = require 'path' os = require 'os' -babelOptions = require '../static/babelrc' # This is the main Gruntfile that manages building N1 distributions. # The reason it's inisde of the build/ folder is so everything can be @@ -51,12 +50,10 @@ _.extend(global, require('harmony-collections')) unless global.WeakMap? module.exports = (grunt) -> grunt.loadNpmTasks('grunt-coffeelint-cjsx') grunt.loadNpmTasks('grunt-lesslint') - grunt.loadNpmTasks('grunt-babel') grunt.loadNpmTasks('grunt-cson') grunt.loadNpmTasks('grunt-contrib-csslint') grunt.loadNpmTasks('grunt-coffee-react') grunt.loadNpmTasks('grunt-contrib-coffee') - grunt.loadNpmTasks('grunt-eslint') grunt.loadNpmTasks('grunt-contrib-less') grunt.loadNpmTasks('grunt-shell') grunt.loadNpmTasks('grunt-markdown') @@ -129,7 +126,7 @@ module.exports = (grunt) -> ext: '.js' babelConfig = - options: babelOptions + options: require("../static/babelrc") dist: files: [{ expand: true diff --git a/build/config/eslint.json b/build/config/eslint.json index c2d4d40ab..d5f23b39b 100644 --- a/build/config/eslint.json +++ b/build/config/eslint.json @@ -1,4 +1,5 @@ { + "parser": "babel-eslint", "extends": "airbnb", "globals": { "NylasEnv": false, @@ -28,6 +29,5 @@ "no-shadow": [1], "quotes": [0], "semi": [0] - }, - "parser": "babel-eslint" + } } diff --git a/build/package.json b/build/package.json index aef93816f..2305f1e76 100644 --- a/build/package.json +++ b/build/package.json @@ -8,19 +8,19 @@ "dependencies": { "asar": "^0.10", "async": "~0.2.9", - "babel-eslint": "^4.1.3", + "babel-eslint": "6.x.x", "bluebird": "^3.0", + "chalk": "1.x.x", "coffee-react-transform": "^3.1.0", "coffeelint-cjsx": "^2.0", "donna": "1.0.10", "escope": "3.3.0", - "eslint": "^1.5.1", - "eslint-config-airbnb": "^0.1.0", - "eslint-plugin-react": "^3.4.2", + "eslint": "2.x.x", + "eslint-config-airbnb": "8.x.x", + "eslint-plugin-react": "5.x.x", "fs-plus": "2.x", "github-releases": "~0.3.0", "grunt": "~0.4.1", - "grunt-babel": "^5.0.1", "grunt-cli": "~0.1.9", "grunt-coffee-react": "^2.1.0", "grunt-coffeelint": "git+https://github.com/atom/grunt-coffeelint.git#cfb99aa99811d52687969532bd5a98011ed95bfe", @@ -31,7 +31,6 @@ "grunt-cson": "0.14.0", "grunt-download-electron": "^2.1", "grunt-electron-installer": "1.2.1", - "grunt-eslint": "^17.3.1", "grunt-lesslint": "0.13.0", "grunt-markdown": "^0.7.0", "grunt-peg": "~1.1.0", diff --git a/build/tasks/babel-task.es6 b/build/tasks/babel-task.es6 new file mode 100644 index 000000000..770f49cda --- /dev/null +++ b/build/tasks/babel-task.es6 @@ -0,0 +1,38 @@ +// Copied from https://github.com/babel/grunt-babel to ensure we always +// use the `babel-core` defined in our own package.json as opposed to the +// grunt-babel dependency's + +const path = require('path'); +const babel = require('babel-core'); + +module.exports = function babelTask(grunt) { + grunt.registerMultiTask('babel', 'Use next generation JavaScript, today', () => { + const options = this.options(); + + this.files.forEach((el) => { + delete options.filename; + delete options.filenameRelative; + + options.sourceFileName = path.relative(path.dirname(el.dest), el.src[0]); + + if (process.platform === 'win32') { + options.sourceFileName = options.sourceFileName.replace(/\\/g, '/'); + } + + options.sourceMapTarget = path.basename(el.dest); + + const res = babel.transformFileSync(el.src[0], options); + let sourceMappingURL = ''; + + if (res.map) { + sourceMappingURL = `\n//# sourceMappingURL=${path.basename(el.dest)}.map`; + } + + grunt.file.write(el.dest, `${res.code}${sourceMappingURL}\n`); + + if (res.map) { + grunt.file.write(`${el.dest}.map`, JSON.stringify(res.map)); + } + }); + }); +}; diff --git a/build/tasks/eslint-task.es6 b/build/tasks/eslint-task.es6 new file mode 100644 index 000000000..1a462f486 --- /dev/null +++ b/build/tasks/eslint-task.es6 @@ -0,0 +1,71 @@ +// Copied from https://github.com/sindresorhus/grunt-eslint +// So we can use our own eslint instead of this tasks's dependency. +const chalk = require('chalk'); +const eslint = require('eslint'); + +module.exports = function eslintTask(grunt) { + grunt.registerMultiTask('eslint', 'Validate files with ESLint', () => { + const opts = this.options({ + outputFile: false, + quiet: false, + maxWarnings: -1, + }); + + // legacy + // TODO: remove in the future + if (opts.config) { + opts.configFile = opts.config; + } + if (opts.rulesdir) { + opts.rulePaths = opts.rulesdir; + } + + if (this.filesSrc.length === 0) { + grunt.log.writeln(chalk.magenta('Could not find any files to validate.')); + return true; + } + + const formatter = eslint.CLIEngine.getFormatter(opts.format); + + if (!formatter) { + grunt.warn(`Could not find formatter ${opts.format}'.`); + return false; + } + + const engine = new eslint.CLIEngine(opts); + + let report; + try { + report = engine.executeOnFiles(this.filesSrc); + } catch (err) { + grunt.warn(err); + return false; + } + + if (opts.fix) { + eslint.CLIEngine.outputFixes(report); + } + + let results = report.results; + + if (opts.quiet) { + results = eslint.CLIEngine.getErrorResults(results); + } + + const output = formatter(results); + + if (opts.outputFile) { + grunt.file.write(opts.outputFile, output); + } else if (output) { + console.log(output); + } + + const tooManyWarnings = opts.maxWarnings >= 0 && report.warningCount > opts.maxWarnings; + + if (report.errorCount === 0 && tooManyWarnings) { + grunt.warn(`ESLint found too many warnings (maximum:${opts.maxWarnings})`); + } + + return report.errorCount === 0; + }); +}; diff --git a/internal_packages/message-list/lib/sidebar-participant-picker.jsx b/internal_packages/message-list/lib/sidebar-participant-picker.jsx index de2d7e83e..6032f9960 100644 --- a/internal_packages/message-list/lib/sidebar-participant-picker.jsx +++ b/internal_packages/message-list/lib/sidebar-participant-picker.jsx @@ -1,5 +1,3 @@ -/** @babel */ - import _ from 'underscore' import React from 'react'; import {Actions, FocusedContactsStore} from 'nylas-exports' diff --git a/internal_packages/participant-profile/lib/sidebar-participant-profile.jsx b/internal_packages/participant-profile/lib/sidebar-participant-profile.jsx index 8eda0616a..1496559b4 100644 --- a/internal_packages/participant-profile/lib/sidebar-participant-profile.jsx +++ b/internal_packages/participant-profile/lib/sidebar-participant-profile.jsx @@ -1,4 +1,3 @@ -/** @babel */ import _ from 'underscore' import React from 'react' import {shell} from 'electron' diff --git a/internal_packages/thread-snooze/lib/snooze-buttons.jsx b/internal_packages/thread-snooze/lib/snooze-buttons.jsx index 218467e35..62fa72163 100644 --- a/internal_packages/thread-snooze/lib/snooze-buttons.jsx +++ b/internal_packages/thread-snooze/lib/snooze-buttons.jsx @@ -1,4 +1,3 @@ -/** @babel */ import React, {Component, PropTypes} from 'react'; import ReactDOM from 'react-dom'; import {Actions, FocusedPerspectiveStore} from 'nylas-exports'; diff --git a/internal_packages/thread-snooze/lib/snooze-popover.jsx b/internal_packages/thread-snooze/lib/snooze-popover.jsx index 5703d3b7a..3a0745e57 100644 --- a/internal_packages/thread-snooze/lib/snooze-popover.jsx +++ b/internal_packages/thread-snooze/lib/snooze-popover.jsx @@ -1,4 +1,3 @@ -/** @babel */ import _ from 'underscore'; import React, {Component, PropTypes} from 'react'; import {DateUtils, Actions} from 'nylas-exports' diff --git a/package.json b/package.json index f4aad7914..feeefb675 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "electronVersion": "0.37.8", "dependencies": { "async": "^0.9", - "babel-core": "^5.8.21", + "babel-core": "6.8.x", "bluebird": "^2.9", "chrono-node": "^1.1.2", "classnames": "1.2.1", diff --git a/spec_integration/jasmine/bootstrap.js b/spec_integration/jasmine/bootstrap.js index 5038e556c..cf2c27f53 100644 --- a/spec_integration/jasmine/bootstrap.js +++ b/spec_integration/jasmine/bootstrap.js @@ -3,7 +3,7 @@ // argv[2] = JASMINE_CONFIG_PATH=./jasmine/config.json // argv[3] = NYLAS_ROOT_PATH=/path/to/nylas/root var babelOptions = require('../../static/babelrc.json'); -require('babel-core/register')(babelOptions); +require('babel-register')(babelOptions); var chalk = require('chalk') var util = require('util') diff --git a/spec_integration/package.json b/spec_integration/package.json index 37d220f60..0fd098f1c 100644 --- a/spec_integration/package.json +++ b/spec_integration/package.json @@ -10,8 +10,8 @@ }, "license": "GPL-3.0", "dependencies": { + "babel-register": "6.8.x", "bluebird": "^3.0.5", - "babel-core": "^5.8.21", "jasmine": "^2.3.2", "spectron": "^0.34.1", "chalk": "^1.1" diff --git a/src/components/nylas-calendar/calendar-event-container.jsx b/src/components/nylas-calendar/calendar-event-container.jsx index aa307e3f6..bcb01e401 100644 --- a/src/components/nylas-calendar/calendar-event-container.jsx +++ b/src/components/nylas-calendar/calendar-event-container.jsx @@ -1,4 +1,3 @@ -/** @babel */ import moment from 'moment' import React from 'react' diff --git a/src/date-utils.es6 b/src/date-utils.es6 index da0628ed1..c92365cfb 100644 --- a/src/date-utils.es6 +++ b/src/date-utils.es6 @@ -1,4 +1,3 @@ -/** @babel */ import moment from 'moment' import chrono from 'chrono-node' import _ from 'underscore'