fix(lint): Correct more linter errors

This commit is contained in:
Ben Gotow 2016-05-06 14:10:28 -07:00
parent 3d3b9bf87f
commit 0e2b5501e3
13 changed files with 76 additions and 69 deletions

View file

@ -8,6 +8,7 @@
"advanceClock": false, "advanceClock": false,
"TEST_ACCOUNT_ID": false, "TEST_ACCOUNT_ID": false,
"TEST_ACCOUNT_NAME": false, "TEST_ACCOUNT_NAME": false,
"TEST_ACCOUNT_EMAIL": false,
"TEST_ACCOUNT_ALIAS_EMAIL": false "TEST_ACCOUNT_ALIAS_EMAIL": false
}, },
"env": { "env": {
@ -17,6 +18,7 @@
}, },
"rules": { "rules": {
"arrow-body-style": "off", "arrow-body-style": "off",
"prefer-arrow-callback": ["error", {"allowNamedFunctions": true}],
"eqeqeq": ["error", "smart"], "eqeqeq": ["error", "smart"],
"id-length": "off", "id-length": "off",
"object-curly-spacing": "off", "object-curly-spacing": "off",
@ -30,6 +32,7 @@
"object-shorthand": "off", "object-shorthand": "off",
"quotes": "off", "quotes": "off",
"quote-props": ["error", "consistent-as-needed", { "keywords": true }], "quote-props": ["error", "consistent-as-needed", { "keywords": true }],
"no-param-reassign": ["error", { "props": false }],
"semi": "off", "semi": "off",
"import/no-unresolved": ["error", {"ignore": ["nylas-exports", "nylas-component-kit", "electron", "nylas-store", "react-dom/server"]}], "import/no-unresolved": ["error", {"ignore": ["nylas-exports", "nylas-component-kit", "electron", "nylas-store", "react-dom/server"]}],
"react/no-multi-comp": "off", "react/no-multi-comp": "off",

View file

@ -23,22 +23,22 @@ describe('DateInput', function dateInput() {
describe('onInputKeyDown', () => { describe('onInputKeyDown', () => {
it('should submit the input if Enter or Escape pressed', () => { it('should submit the input if Enter or Escape pressed', () => {
const onSubmitDate = jasmine.createSpy('onSubmitDate') const onSubmitDate = jasmine.createSpy('onSubmitDate')
const dateInput = makeInput({onSubmitDate: onSubmitDate}) const component = makeInput({onSubmitDate: onSubmitDate})
const inputNode = ReactDOM.findDOMNode(dateInput).querySelector('input') const inputNode = ReactDOM.findDOMNode(component).querySelector('input')
const stopPropagation = jasmine.createSpy('stopPropagation') const stopPropagation = jasmine.createSpy('stopPropagation')
const keys = ['Enter', 'Return'] const keys = ['Enter', 'Return']
inputNode.value = 'tomorrow' inputNode.value = 'tomorrow'
spyOn(DateUtils, 'futureDateFromString').andReturn('someday') spyOn(DateUtils, 'futureDateFromString').andReturn('someday')
spyOn(dateInput, 'setState') spyOn(component, 'setState')
keys.forEach((key) => { keys.forEach((key) => {
Simulate.keyDown(inputNode, {key, stopPropagation}) Simulate.keyDown(inputNode, {key, stopPropagation})
expect(stopPropagation).toHaveBeenCalled() expect(stopPropagation).toHaveBeenCalled()
expect(onSubmitDate).toHaveBeenCalledWith('someday', 'tomorrow') expect(onSubmitDate).toHaveBeenCalledWith('someday', 'tomorrow')
expect(dateInput.setState).toHaveBeenCalledWith({inputDate: null}) expect(component.setState).toHaveBeenCalledWith({inputDate: null})
stopPropagation.reset() stopPropagation.reset()
onSubmitDate.reset() onSubmitDate.reset()
dateInput.setState.reset() component.setState.reset()
}) })
}); });
}); });
@ -49,18 +49,18 @@ describe('DateInput', function dateInput() {
}); });
it('should render a date interpretation if a date has been inputted', () => { it('should render a date interpretation if a date has been inputted', () => {
const dateInput = makeInput({initialState: {inputDate: 'something!'}}) const component = makeInput({initialState: {inputDate: 'something!'}})
spyOn(dateInput, 'setState') spyOn(component, 'setState')
const dateInterpretation = findDOMNode(findRenderedDOMComponentWithClass(dateInput, 'date-interpretation')) const dateInterpretation = findDOMNode(findRenderedDOMComponentWithClass(component, 'date-interpretation'))
expect(dateInterpretation.textContent).toEqual('formatted') expect(dateInterpretation.textContent).toEqual('formatted')
}); });
it('should not render a date interpretation if no input date available', () => { it('should not render a date interpretation if no input date available', () => {
const dateInput = makeInput({initialState: {inputDate: null}}) const component = makeInput({initialState: {inputDate: null}})
spyOn(dateInput, 'setState') spyOn(component, 'setState')
expect(() => { expect(() => {
findRenderedDOMComponentWithClass(dateInput, 'date-interpretation') findRenderedDOMComponentWithClass(component, 'date-interpretation')
}).toThrow() }).toThrow()
}); });
}); });

View file

@ -6,8 +6,13 @@ import {renderIntoDocument} from '../nylas-test-utils'
const {Directions: {Up, Down, Left, Right}} = FixedPopover const {Directions: {Up, Down, Left, Right}} = FixedPopover
const makePopover = (props = {}) => { const makePopover = (props = {}) => {
props.originRect = props.originRect ? props.originRect : {}; const originRect = props.originRect ? props.originRect : {};
const popover = renderIntoDocument(<FixedPopover {...props}/>); const popover = renderIntoDocument(
<FixedPopover
{...props}
originRect={originRect}
/>
);
if (props.initialState) { if (props.initialState) {
popover.setState(props.initialState) popover.setState(props.initialState)
} }

View file

@ -3,10 +3,7 @@ import {InjectedComponentSet} from 'nylas-component-kit';
const {renderIntoDocument} = NylasTestUtils; const {renderIntoDocument} = NylasTestUtils;
const reactStub = (displayName) => { const reactStub = (displayName) => {
return React.createClass({ return <div className={displayName}></div>;
displayName,
render() { return <div className={displayName}></div>; },
});
}; };
@ -26,7 +23,8 @@ describe('InjectedComponentSet', function injectedComponentSet() {
renderIntoDocument( renderIntoDocument(
<InjectedComponentSet <InjectedComponentSet
matching={{}} matching={{}}
onComponentsDidRender={onComponentsDidRender} /> onComponentsDidRender={onComponentsDidRender}
/>
); );
}); });

View file

@ -1,5 +1,5 @@
import {events} from './fixtures/events' // import {events} from './fixtures/events'
import {NylasCalendar} from 'nylas-component-kit' // import {NylasCalendar} from 'nylas-component-kit'
//
describe('Extended Nylas Calendar Week View', function extendedNylasCalendarWeekView() { // describe('Extended Nylas Calendar Week View', function extendedNylasCalendarWeekView() {
}); // });

View file

@ -121,10 +121,8 @@ describe("Nylas Calendar Week View", function weekViewSpec() {
// See fixtures/events // See fixtures/events
expect(eventsByDay.allDay.length).toBe(numAllDayEvents); expect(eventsByDay.allDay.length).toBe(numAllDayEvents);
for (const day in numByDay) { for (const day of Object.keys(numByDay)) {
if (numByDay.hasOwnProperty(day)) { expect(eventsByDay[day].length).toBe(numByDay[day])
expect(eventsByDay[day].length).toBe(numByDay[day])
}
} }
}); });

View file

@ -16,11 +16,12 @@ import {
SyncbackDraftFilesTask, SyncbackDraftFilesTask,
} from 'nylas-exports'; } from 'nylas-exports';
import {remote} from 'electron';
import DraftFactory from '../../src/flux/stores/draft-factory'; import DraftFactory from '../../src/flux/stores/draft-factory';
class TestExtension extends ComposerExtension { class TestExtension extends ComposerExtension {
static prepareNewDraft({draft}) { static prepareNewDraft({draft}) {
draft.body = "Edited by TestExtension!" + draft.body; draft.body = `Edited by TestExtension! ${draft.body}`;
} }
} }
@ -180,7 +181,7 @@ describe('DraftStore', function draftStore() {
}, },
teardown: this.draftSessionTeardown, teardown: this.draftSessionTeardown,
}; };
DraftStore._draftSessions = {"abc": this.session}; DraftStore._draftSessions = {abc: this.session};
spyOn(Actions, 'queueTask'); spyOn(Actions, 'queueTask');
}); });
@ -222,12 +223,14 @@ describe('DraftStore', function draftStore() {
describe("before unloading", () => { describe("before unloading", () => {
it("should destroy pristine drafts", () => { it("should destroy pristine drafts", () => {
DraftStore._draftSessions = {"abc": { DraftStore._draftSessions = {
changes: {}, abc: {
draft() { changes: {},
return {pristine: true}; draft() {
return {pristine: true};
},
}, },
}}; };
spyOn(Actions, 'queueTask'); spyOn(Actions, 'queueTask');
DraftStore._onBeforeUnload(); DraftStore._onBeforeUnload();
@ -239,9 +242,9 @@ describe('DraftStore', function draftStore() {
beforeEach(() => { beforeEach(() => {
this.resolve = null; this.resolve = null;
DraftStore._draftSessions = { DraftStore._draftSessions = {
"abc": { abc: {
changes: { changes: {
commit: () => new Promise((resolve) => this.resolve = resolve), commit: () => new Promise((resolve) => { this.resolve = resolve }),
}, },
draft() { draft() {
return {pristine: false}; return {pristine: false};
@ -262,13 +265,15 @@ describe('DraftStore', function draftStore() {
describe("when drafts return immediately fulfilled commit promises", () => { describe("when drafts return immediately fulfilled commit promises", () => {
beforeEach(() => { beforeEach(() => {
DraftStore._draftSessions = {"abc": { DraftStore._draftSessions = {
changes: abc: {
{commit: () => Promise.resolve()}, changes:
draft() { {commit: () => Promise.resolve()},
return {pristine: false}; draft() {
return {pristine: false};
},
}, },
}}; };
}); });
it("should still wait one tick before firing NylasEnv.close again", () => { it("should still wait one tick before firing NylasEnv.close again", () => {
@ -429,7 +434,6 @@ describe('DraftStore', function draftStore() {
it("displays a popup in the main window if there's an error", () => { it("displays a popup in the main window if there's an error", () => {
spyOn(NylasEnv, "isMainWindow").andReturn(true); spyOn(NylasEnv, "isMainWindow").andReturn(true);
spyOn(FocusedContentStore, "focused").andReturn({id: "t1"}); spyOn(FocusedContentStore, "focused").andReturn({id: "t1"});
const {remote} = require('electron');
spyOn(remote.dialog, "showMessageBox"); spyOn(remote.dialog, "showMessageBox");
spyOn(Actions, "composePopoutDraft"); spyOn(Actions, "composePopoutDraft");
DraftStore._draftsSending[this.draft.clientId] = true; DraftStore._draftsSending[this.draft.clientId] = true;
@ -485,7 +489,7 @@ describe('DraftStore', function draftStore() {
}, },
teardown: this.draftTeardown, teardown: this.draftTeardown,
}; };
DraftStore._draftSessions = {"abc": this.session}; DraftStore._draftSessions = {abc: this.session};
DraftStore._doneWithSession(this.session); DraftStore._doneWithSession(this.session);
}); });

View file

@ -65,7 +65,7 @@ describe('NylasSyncStatusStore', function nylasSyncStatusStore() {
}); });
it('returns false otherwise', () => { it('returns false otherwise', () => {
spyOn(store, 'isSyncCompleteForAccount').andCallFake((acctId) => acctId === 'a1' ? true : false) spyOn(store, 'isSyncCompleteForAccount').andCallFake(acctId => acctId === 'a1')
store._statesByAccount = { store._statesByAccount = {
a1: {}, a1: {},
a2: {}, a2: {},

View file

@ -22,7 +22,7 @@ export class APITestTask extends Task {
} }
export class KillsTaskA extends Task { export class KillsTaskA extends Task {
shouldDequeueOtherTask(other) {return other instanceof TaskSubclassA} shouldDequeueOtherTask(other) { return other instanceof TaskSubclassA }
performRemote() { return new Promise(() => {}) } performRemote() { return new Promise(() => {}) }
} }
@ -50,10 +50,9 @@ export class TaskBB extends Task {
} }
export class OKTask extends Task { export class OKTask extends Task {
performRemote() {return Promise.resolve(Task.Status.Retry)} performRemote() { return Promise.resolve(Task.Status.Retry) }
} }
export class BadTask extends Task { export class BadTask extends Task {
performRemote() {return Promise.resolve('lalal')} performRemote() { return Promise.resolve('lalal') }
} }

View file

@ -13,14 +13,14 @@ describe('TaskFactory', function taskFactory() {
beforeEach(() => { beforeEach(() => {
this.categories = { this.categories = {
'ac-1': { 'ac-1': {
'archive': new Category({name: 'archive'}), archive: new Category({name: 'archive'}),
'inbox': new Category({name: 'inbox1'}), inbox: new Category({name: 'inbox1'}),
'trash': new Category({name: 'trash1'}), trash: new Category({name: 'trash1'}),
}, },
'ac-2': { 'ac-2': {
'archive': new Category({name: 'all'}), archive: new Category({name: 'all'}),
'inbox': new Category({name: 'inbox2'}), inbox: new Category({name: 'inbox2'}),
'trash': new Category({name: 'trash2'}), trash: new Category({name: 'trash2'}),
}, },
} }
this.accounts = { this.accounts = {

View file

@ -248,10 +248,9 @@ describe('SendDraftTask', function sendDraftTask() {
if (options.body.reply_to_message_id) { if (options.body.reply_to_message_id) {
const err = new APIError({body: "Invalid message public id"}); const err = new APIError({body: "Invalid message public id"});
return Promise.reject(err); return Promise.reject(err);
} else {
if (options.success) { options.success(this.response) }
return Promise.resolve(this.response);
} }
if (options.success) { options.success(this.response) }
return Promise.resolve(this.response);
}); });
this.draft.replyToMessageId = "reply-123"; this.draft.replyToMessageId = "reply-123";
@ -273,10 +272,9 @@ describe('SendDraftTask', function sendDraftTask() {
spyOn(NylasAPI, 'makeRequest').andCallFake((options) => { spyOn(NylasAPI, 'makeRequest').andCallFake((options) => {
if (options.body.reply_to_message_id) { if (options.body.reply_to_message_id) {
return Promise.reject(new APIError({body: "Invalid thread"})); return Promise.reject(new APIError({body: "Invalid thread"}));
} else {
if (options.success) { options.success(this.response) }
return Promise.resolve(this.response);
} }
if (options.success) { options.success(this.response) }
return Promise.resolve(this.response);
}); });
this.draft.replyToMessageId = "reply-123"; this.draft.replyToMessageId = "reply-123";
@ -356,7 +354,7 @@ describe('SendDraftTask', function sendDraftTask() {
body: { body: {
message: "Sending to at least one recipient failed.", message: "Sending to at least one recipient failed.",
server_error: "<<Don't know what this looks like >>", server_error: "<<Don't know what this looks like >>",
type: "api_error" type: "api_error",
}, },
}) })

View file

@ -67,8 +67,8 @@ describe('SyncbackDraftFilesTask', function syncbackDraftFilesTask() {
// uploads should be queued, but not the send // uploads should be queued, but not the send
expect(NylasAPI.makeRequest.callCount).toEqual(2); expect(NylasAPI.makeRequest.callCount).toEqual(2);
expect(NylasAPI.makeRequest.calls[0].args[0].formData).toEqual({ file : { value : 'stub', options : { filename : 'test-file-1.png' } } }); expect(NylasAPI.makeRequest.calls[0].args[0].formData).toEqual({file: {value: 'stub', options: { filename: 'test-file-1.png' } } });
expect(NylasAPI.makeRequest.calls[1].args[0].formData).toEqual({ file : { value : 'stub', options : { filename : 'test-file-2.png' } } }); expect(NylasAPI.makeRequest.calls[1].args[0].formData).toEqual({file: {value: 'stub', options: { filename: 'test-file-2.png' } } });
// finish all uploads // finish all uploads
expect(taskPromise.isFulfilled()).toBe(false); expect(taskPromise.isFulfilled()).toBe(false);

View file

@ -165,8 +165,8 @@ export default class TimePicker extends React.Component {
while (timeIter.isSameOrBefore(endMoment)) { while (timeIter.isSameOrBefore(endMoment)) {
const val = timeIter.valueOf(); const val = timeIter.valueOf();
const className = classnames({ const className = classnames({
option: true, "option": true,
selected: timeIter.isSame(enteredMoment), "selected": timeIter.isSame(enteredMoment),
"scroll-start": timeIter.isSame(firstVisibleMoment), "scroll-start": timeIter.isSame(firstVisibleMoment),
}) })
@ -180,7 +180,8 @@ export default class TimePicker extends React.Component {
} }
opts.push( opts.push(
<div className={className} key={val} <div
className={className} key={val}
onMouseDown={() => this._onSelectOption(val)} onMouseDown={() => this._onSelectOption(val)}
> >
{timeIter.format("LT")}{relTxt} {timeIter.format("LT")}{relTxt}
@ -203,11 +204,12 @@ export default class TimePicker extends React.Component {
const className = classnames({ const className = classnames({
"time-picker": true, "time-picker": true,
"no-select-end": true, "no-select-end": true,
invalid: !moment(this.state.rawText, "h:ma").isValid(), "invalid": !moment(this.state.rawText, "h:ma").isValid(),
}) })
return ( return (
<div className="time-picker-wrap"> <div className="time-picker-wrap">
<input className={className} <input
className={className}
type="text" type="text"
ref="input" ref="input"
value={this.state.rawText} value={this.state.rawText}