Skip to content

Commit

Permalink
Revert "Revert "ESLint for great justice: Episode I""
Browse files Browse the repository at this point in the history
This reverts commit 45e7b21.
  • Loading branch information
j-f1 committed Oct 19, 2017
1 parent a6fcd1a commit 254c566
Show file tree
Hide file tree
Showing 65 changed files with 945 additions and 416 deletions.
87 changes: 87 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
root: true
parser: typescript-eslint-parser
plugins:
- typescript
- babel
- react
- prettier

extends:
- prettier
- prettier/react

rules:
##########
# CUSTOM #
##########
insecure-random: error

###########
# PLUGINS #
###########
# TYPESCRIPT
typescript/interface-name-prefix:
- error
- always
typescript/no-angle-bracket-type-assertion: error
typescript/explicit-member-accessibility: error
typescript/no-unused-vars: error
typescript/no-use-before-define:
- error
- functions: false
variables: false
typedefs: false
## blocked by https://github.com/nzakas/eslint-plugin-typescript/pull/23
# typescript/member-ordering: error
##
## blocked by https://github.com/nzakas/eslint-plugin-typescript/issues/41
# typescript/type-annotation-spacing: error
##

# Babel
babel/no-invalid-this: error

# React
react/jsx-boolean-value:
- error
- always
react/jsx-key: error
react/jsx-no-bind: error
react/no-string-refs: error

###########
# BUILTIN #
###########
curly: error
no-new-wrappers: error
no-redeclare:
- error
- builtinGlobals: true
no-eval: error
no-sync: error
no-unused-expressions: error
no-var: error
prefer-const: error
eqeqeq:
- error
- smart

###########
# SPECIAL #
###########
prettier/prettier:
- error
- singleQuote: true
trailingComma: es5
semi: false
parser: typescript
no-restricted-syntax:
- error
# no-default-export
- selector: ExportDefaultDeclaration
message: Use of default exports is forbidden

parserOptions:
sourceType: module
ecmaFeatures:
jsx: true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ app/node_modules/
.DS_Store
.awcache
.idea/
.eslintcache
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ cache:
directories:
- node_modules
- $HOME/.electron
- .eslintcache

install:
- npm install -g yarn@1.2.1
- yarn install --force

script:
- yarn check-prettiness
- yarn lint
- yarn build:prod
- yarn test:setup
Expand Down
16 changes: 8 additions & 8 deletions app/src/lib/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ declare type DOMHighResTimeStamp = number
*
* https://developer.mozilla.org/en-US/docs/Web/API/IdleDeadline
*/
interface IdleDeadline {
interface IIdleDeadline {
readonly didTimeout: boolean
readonly timeRemaining: () => DOMHighResTimeStamp
}
Expand All @@ -75,7 +75,7 @@ interface IdleDeadline {
*
* See https://developer.mozilla.org/en-US/docs/Web/API/Window/requestIdleCallback
*/
interface IdleCallbackOptions {
interface IIdleCallbackOptions {
/**
* If timeout is specified and has a positive value, and the callback has not
* already been called by the time timeout milliseconds have passed, the
Expand All @@ -101,8 +101,8 @@ interface IdleCallbackOptions {
* timeout:
*/
declare function requestIdleCallback(
fn: (deadline: IdleDeadline) => void,
options?: IdleCallbackOptions
fn: (deadline: IIdleDeadline) => void,
options?: IIdleCallbackOptions
): number

interface IDesktopLogger {
Expand Down Expand Up @@ -179,7 +179,7 @@ declare const log: IDesktopLogger
// these changes should be pushed into the Electron declarations

declare namespace NodeJS {
// tslint:disable-next-line:interface-name
// eslint-disable-next-line typescript/interface-name-prefix
interface Process extends EventEmitter {
once(event: 'uncaughtException', listener: (error: Error) => void): this
on(event: 'uncaughtException', listener: (error: Error) => void): this
Expand All @@ -189,15 +189,15 @@ declare namespace NodeJS {
}

declare namespace Electron {
// tslint:disable-next-line:interface-name
// eslint-disable-next-line typescript/interface-name-prefix
interface MenuItem {
readonly accelerator?: Electron.Accelerator
readonly submenu?: Electron.Menu
readonly role?: string
readonly type: 'normal' | 'separator' | 'submenu' | 'checkbox' | 'radio'
}

// tslint:disable-next-line:interface-name
// eslint-disable-next-line typescript/interface-name-prefix
interface RequestOptions {
readonly method: string
readonly url: string
Expand All @@ -206,7 +206,7 @@ declare namespace Electron {

type AppleActionOnDoubleClickPref = 'Maximize' | 'Minimize' | 'None'

// tslint:disable-next-line:interface-name
// eslint-disable-next-line typescript/interface-name-prefix
interface SystemPreferences {
getUserDefault(
key: 'AppleActionOnDoubleClick',
Expand Down
4 changes: 2 additions & 2 deletions app/src/lib/logging/main/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { formatLogMessage } from '../format-log-message'

const g = global as any

g.log = <IDesktopLogger>{
g.log = {
error(message: string, error?: Error) {
log('error', '[main] ' + formatLogMessage(message, error))
},
Expand All @@ -16,4 +16,4 @@ g.log = <IDesktopLogger>{
debug(message: string, error?: Error) {
log('debug', '[main] ' + formatLogMessage(message, error))
},
}
} as IDesktopLogger
4 changes: 2 additions & 2 deletions app/src/lib/logging/renderer/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function log(level: LogLevel, message: string, error?: Error) {
)
}

g.log = <IDesktopLogger>{
g.log = {
error(message: string, error?: Error) {
log('error', message, error)
console.error(formatLogMessage(message, error))
Expand All @@ -34,4 +34,4 @@ g.log = <IDesktopLogger>{
log('debug', message, error)
console.debug(formatLogMessage(message, error))
},
}
} as IDesktopLogger
2 changes: 1 addition & 1 deletion app/src/lib/shell.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* tslint:disable:no-sync-functions */
/* eslint-disable no-sync */

import * as ChildProcess from 'child_process'
import * as os from 'os'
Expand Down
5 changes: 2 additions & 3 deletions app/src/lib/source-map-support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ function retrieveSourceMap(source: string) {
// https://github.com/v8/v8/wiki/Stack-Trace-API#customizing-stack-traces
// This happens on-demand when someone accesses the stack
// property on an error object and has to be synchronous :/
// tslint:disable-next-line:no-sync-functions
// eslint-disable-next-line no-sync
if (!Fs.existsSync(path)) {
return
}

try {
// tslint:disable-next-line:no-sync-functions
// eslint-disable-next-line no-sync
const map = Fs.readFileSync(path, 'utf8')
return { url: Path.basename(path), map }
} catch (error) {
Expand Down Expand Up @@ -125,7 +125,6 @@ function sourceMappedStackTrace(error: Error): string | undefined {
// in our weak map. In order to get around that we'll eagerly access the
// stack, forcing our handler to run which should ensure that the native
// frames are stored in our weak map.
// tslint:disable-next-line:whitespace
;(error.stack || '').toString()
frames = stackFrameMap.get(error)
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/lib/stores/helpers/background-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ function skewInterval(): number {

// We don't need cryptographically secure random numbers for
// the skew. Pseudo-random should be just fine.
// tslint:disable-next-line:insecure-random
// eslint-disable-next-line insecure-random
const skew = Math.ceil(Math.random() * SkewUpperBound)
_skewInterval = skew
return skew
Expand Down
78 changes: 39 additions & 39 deletions app/src/models/diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,45 @@ import { assertNever } from '../lib/fatal-error'
*/
export const maximumDiffStringSize = 268435441

/**
* A container for holding an image for display in the application
*/
export class Image {
/**
* The base64 encoded contents of the image
*/
public readonly contents: string

/**
* The data URI media type, so the browser can render the image correctly
*/
public readonly mediaType: string
}

/** each diff is made up of a number of hunks */
export class DiffHunk {
/** details from the diff hunk header about the line start and patch length */
public readonly header: DiffHunkHeader
/** the contents - context and changes - of the diff setion */
public readonly lines: ReadonlyArray<DiffLine>
/** the diff hunk's start position in the overall file diff */
public readonly unifiedDiffStart: number
/** the diff hunk's end position in the overall file diff */
public readonly unifiedDiffEnd: number

public constructor(
header: DiffHunkHeader,
lines: ReadonlyArray<DiffLine>,
unifiedDiffStart: number,
unifiedDiffEnd: number
) {
this.header = header
this.unifiedDiffStart = unifiedDiffStart
this.unifiedDiffEnd = unifiedDiffEnd
this.lines = lines
}
}

export enum DiffType {
/** changes to a text file, which may be partially selected for commit */
Text,
Expand Down Expand Up @@ -162,45 +201,6 @@ export class DiffHunkHeader {
}
}

/** each diff is made up of a number of hunks */
export class DiffHunk {
/** details from the diff hunk header about the line start and patch length */
public readonly header: DiffHunkHeader
/** the contents - context and changes - of the diff setion */
public readonly lines: ReadonlyArray<DiffLine>
/** the diff hunk's start position in the overall file diff */
public readonly unifiedDiffStart: number
/** the diff hunk's end position in the overall file diff */
public readonly unifiedDiffEnd: number

public constructor(
header: DiffHunkHeader,
lines: ReadonlyArray<DiffLine>,
unifiedDiffStart: number,
unifiedDiffEnd: number
) {
this.header = header
this.unifiedDiffStart = unifiedDiffStart
this.unifiedDiffEnd = unifiedDiffEnd
this.lines = lines
}
}

/**
* A container for holding an image for display in the application
*/
export class Image {
/**
* The base64 encoded contents of the image
*/
public readonly contents: string

/**
* The data URI media type, so the browser can render the image correctly
*/
public readonly mediaType: string
}

export class FileSummary {
/**
* The number of lines added as part of this change.
Expand Down
2 changes: 1 addition & 1 deletion app/src/ui/add-repository/add-existing-repository.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { LinkButton } from '../lib/link-button'
import { PopupType } from '../../lib/app-state'
import * as Path from 'path'

const untildify: (str: string) => string = require('untildify')
import untildify = require('untildify')

interface IAddExistingRepositoryProps {
readonly dispatcher: Dispatcher
Expand Down
16 changes: 10 additions & 6 deletions app/src/ui/app-menu/app-menu-bar.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import * as React from 'react'
import { IMenu, ISubmenuItem } from '../../models/app-menu'
import {
IMenu,
ISubmenuItem,
findItemByAccessKey,
itemIsSelectable,
} from '../../models/app-menu'
import { AppMenuBarButton } from './app-menu-bar-button'
import { Dispatcher } from '../../lib/dispatcher'
import { AppMenuFoldout, FoldoutType } from '../../lib/app-state'
import { findItemByAccessKey, itemIsSelectable } from '../../models/app-menu'

interface IAppMenuBarProps {
readonly appMenu: ReadonlyArray<IMenu>
Expand All @@ -27,7 +31,7 @@ interface IAppMenuBarProps {

/**
* An optional function that's called when the menubar loses focus.
*
*
* Note that this function will only be called once no descendant element
* of the menu bar has keyboard focus. In other words this differs
* from the traditional onBlur event.
Expand All @@ -47,7 +51,7 @@ interface IAppMenuBarState {
* Creates menu bar state given props. This is intentionally not
* an instance member in order to avoid mistakenly using any other
* input data or state than the received props.
*
*
* The state consists of a list of visible top-level menu items which have
* child menus of their own (ie submenu items).
*/
Expand Down Expand Up @@ -95,12 +99,12 @@ export class AppMenuBar extends React.Component<
* element which had focus prior to the component receiving it. We do so in
* order to be able to restore focus to that element when we decide to
* _programmatically_ give up our focus.
*
*
* A good example of this is when the user is focused on a text box and hits
* the Alt key. Focus will then move to the first menu item in the menu bar.
* If the user then hits Enter we relinquish our focus and return it back to
* the text box again.
*
*
* As long as we hold on to this reference we might be preventing GC from
* collecting a potentially huge subtree of the DOM so we need to make sure
* to clear it out as soon as we're done with it.
Expand Down
Loading

0 comments on commit 254c566

Please sign in to comment.