diff --git a/build/tasks/nylaslint-task.coffee b/build/tasks/nylaslint-task.coffee index db30fa475..d6f640a6e 100644 --- a/build/tasks/nylaslint-task.coffee +++ b/build/tasks/nylaslint-task.coffee @@ -19,37 +19,62 @@ module.exports = (grunt) -> ".cjsx": true } - esSet = {} - for f in fileset.src - if esExtensions[path.extname(f)] - esSet[path.basename(f, path.extname(f))] = true - blacklist = ["events", "main", "package", "task"] - delete esSet[item] for item in blacklist - errors = [] + esExport = {} + esNoExport = {} + esExportDefault = {} + + for f in fileset.src + continue if not esExtensions[path.extname(f)] + fname = path.basename(f, path.extname(f)) + + content = fs.readFileSync(f, encoding:'utf8') + if /module.exports\s?=\s?.+/gmi.test(content) + errors.push("#{f}: Don't use module.exports in ES6") + + if /^export/gmi.test(content) + if /^export\ default/gmi.test(content) + esExportDefault[fname] = true + else + esExport[fname] = true + else + esNoExport[fname] = true + + blacklist = ["events", "main", "package", "task"] + for item in blacklist + delete esExportDefault[item] + delete esExport[item] + delete esNoExport[item] + # file.src is the list of all matching file names. for f in fileset.src - if esExtensions[path.extname(f)] - content = fs.readFileSync(f, encoding:'utf8') - if /module.exports\s?=\s?.+/.test(content) - errors.push("#{f}: Don't use module.exports in ES6") - else - content = fs.readFileSync(f, encoding:'utf8') - if extensionRegex.test(content) - errors.push("#{f}: Remove require extension!") + continue if esExtensions[path.extname(f)] + content = fs.readFileSync(f, encoding:'utf8') + if extensionRegex.test(content) + errors.push("#{f}: Remove require extension!") - requireRe = /require[\s()]['"](.*)['"]/gmi - while result = requireRe.exec(content) - i = 1 - while i < result.length - requirePath = result[i] - i += 1 - baseRequirePath = path.basename(requirePath) - if esSet[baseRequirePath] - testForPath = new RegExp("require\\(['\"].*#{baseRequirePath}['\"]\\)\\.","gm") - if not testForPath.test(content) - errors.push("#{f}: ES6 add `default` to require #{requirePath}") + requireRe = /require[ (]['"]([\w_./-]*?)['"]/gmi + while result = requireRe.exec(content) + i = 1 + while i < result.length + requirePath = result[i] + i += 1 + baseRequirePath = path.basename(requirePath) + + plainRequireRe = new RegExp("require[ (]['\"].*#{baseRequirePath}['\"]\\)?$","gm") + defaultRequireRe = new RegExp("require\\(['\"].*#{baseRequirePath}['\"]\\)\\.default","gm") + + if esExport[baseRequirePath] + if not plainRequireRe.test(content) + errors.push("#{f}: ES6 no `default` exported #{requirePath}") + + if esNoExport[baseRequirePath] + errors.push("#{f}: nothing exported from #{requirePath}") + + if esExportDefault[baseRequirePath] + if not defaultRequireRe.test(content) + errors.push("#{f}: ES6 add `default` to require #{requirePath}") if errors.length > 0 grunt.log.error(err) for err in errors diff --git a/spec/extension-registry-spec.coffee b/spec/extension-registry-spec.coffee index c5c2d1c97..609e6d805 100644 --- a/spec/extension-registry-spec.coffee +++ b/spec/extension-registry-spec.coffee @@ -1,4 +1,4 @@ -ExtensionRegistry = require('../src/extension-registry').default +ExtensionRegistry = require('../src/extension-registry') class TestExtension @name: 'TestExtension' diff --git a/src/flux/stores/draft-editing-session.coffee b/src/flux/stores/draft-editing-session.coffee index bfe0457ed..74d7421f7 100644 --- a/src/flux/stores/draft-editing-session.coffee +++ b/src/flux/stores/draft-editing-session.coffee @@ -1,7 +1,7 @@ Message = require '../models/message' Actions = require '../actions' DatabaseStore = require './database-store' -ExtensionRegistry = require('../../extension-registry').default +ExtensionRegistry = require('../../extension-registry') {Listener, Publisher} = require '../modules/reflux-coffee' SyncbackDraftTask = require('../tasks/syncback-draft-task').default CoffeeHelpers = require '../coffee-helpers' diff --git a/src/flux/stores/draft-store.coffee b/src/flux/stores/draft-store.coffee index 8e59a5928..b8e444026 100644 --- a/src/flux/stores/draft-store.coffee +++ b/src/flux/stores/draft-store.coffee @@ -27,7 +27,7 @@ SoundRegistry = require '../../sound-registry' {Listener, Publisher} = require '../modules/reflux-coffee' CoffeeHelpers = require '../coffee-helpers' -ExtensionRegistry = require('../../extension-registry').default +ExtensionRegistry = require('../../extension-registry') {deprecate} = require '../../deprecate-utils' ### diff --git a/src/flux/stores/message-store.coffee b/src/flux/stores/message-store.coffee index 946d417a0..bebb919d7 100644 --- a/src/flux/stores/message-store.coffee +++ b/src/flux/stores/message-store.coffee @@ -8,7 +8,7 @@ FocusedPerspectiveStore = require './focused-perspective-store' FocusedContentStore = require "./focused-content-store" ChangeUnreadTask = require('../tasks/change-unread-task').default NylasAPI = require '../nylas-api' -ExtensionRegistry = require('../../extension-registry').default +ExtensionRegistry = require('../../extension-registry') {deprecate} = require '../../deprecate-utils' async = require 'async' _ = require 'underscore'