Style: extra linting

This commit is contained in:
DC
2016-08-31 14:13:43 -07:00
parent e0af554caa
commit 0bda5358bd
11 changed files with 98 additions and 25 deletions

47
bin/extra-lint.js Executable file
View File

@@ -0,0 +1,47 @@
#!/usr/bin/env node
const walkSync = require('walk-sync')
const fs = require('fs')
const path = require('path')
let hasErrors = false
// Find all Javascript source files
var files = walkSync('src', {globs: ['**/*.js']})
console.log('Running extra-lint on ' + files.length + ' files...')
// Read each file, line by line
files.forEach(function (file) {
var filepath = path.join('src', file)
var lines = fs.readFileSync(filepath, 'utf8').split('\n')
lines.forEach(function (line, i) {
var error
// Consistent JSX tag closing
if (line.match(/' {2}\/> *$/) ||
line.match('[^ ]/> *$') ||
line.match(' > *$')) {
error = 'JSX tag spacing'
}
// No lines over 100 characters
if (line.length > 100) {
error = 'Line >100 chars'
}
// TODO: No vars
// if (line.match(/^var /) || line.match(/ var /)) {
// error = 'Use const or let'
// }
if (error) {
let name = path.basename(file)
console.log('%s:%d - %s:\n%s', name, i + 1, error, line)
hasErrors = true
}
})
})
if (hasErrors) process.exit(1)
else console.log('Looks good!')

View File

@@ -65,7 +65,8 @@
"plist": "^2.0.1", "plist": "^2.0.1",
"rimraf": "^2.5.2", "rimraf": "^2.5.2",
"run-series": "^1.1.4", "run-series": "^1.1.4",
"standard": "*" "standard": "*",
"walk-sync": "^0.3.1"
}, },
"engines": { "engines": {
"node": ">=4.0.0" "node": ">=4.0.0"
@@ -98,7 +99,7 @@
"package": "node ./bin/package.js", "package": "node ./bin/package.js",
"prepublish": "npm run build", "prepublish": "npm run build",
"start": "npm run build && electron .", "start": "npm run build && electron .",
"test": "standard && depcheck --ignores=babel-cli,nodemon,gh-release --ignore-dirs=build,dist", "test": "standard && depcheck --ignores=babel-cli,nodemon,gh-release --ignore-dirs=build,dist && node ./bin/extra-lint.js",
"gh-release": "gh-release", "gh-release": "gh-release",
"update-authors": "./bin/update-authors.sh", "update-authors": "./bin/update-authors.sh",
"watch": "nodemon --exec 'npm run start' --ext js,pug,css" "watch": "nodemon --exec 'npm run start' --ext js,pug,css"

View File

@@ -26,7 +26,13 @@ function spawn (path, url, title) {
// Try to find and use VLC if external player is not specified // Try to find and use VLC if external player is not specified
vlcCommand(function (err, vlcPath) { vlcCommand(function (err, vlcPath) {
if (err) return windows.main.dispatch('externalPlayerNotFound') if (err) return windows.main.dispatch('externalPlayerNotFound')
var args = ['--play-and-exit', '--video-on-top', '--quiet', `--meta-title=${JSON.stringify(title)}`, url] var args = [
'--play-and-exit',
'--video-on-top',
'--quiet',
`--meta-title=${JSON.stringify(title)}`,
url
]
spawnExternal(vlcPath, args) spawnExternal(vlcPath, args)
}) })
} }

View File

@@ -15,9 +15,10 @@ module.exports = class UnsupportedMediaModal extends React.Component {
var playerName = playerPath var playerName = playerPath
? path.basename(playerPath).split('.')[0] ? path.basename(playerPath).split('.')[0]
: 'VLC' : 'VLC'
var onPlay = dispatcher('openExternalPlayer')
var actionButton = state.modal.externalPlayerInstalled var actionButton = state.modal.externalPlayerInstalled
? (<button className='button-raised' onClick={dispatcher('openExternalPlayer')}>Play in {playerName}</button>) ? (<button className='button-raised' onClick={onPlay}>Play in {playerName}</button>)
: (<button className='button-raised' onClick={() => this.onInstall}>Install VLC</button>) : (<button className='button-raised' onClick={() => this.onInstall()}>Install VLC</button>)
var playerMessage = state.modal.externalPlayerNotFound var playerMessage = state.modal.externalPlayerNotFound
? 'Couldn\'t run external player. Please make sure it\'s installed.' ? 'Couldn\'t run external player. Please make sure it\'s installed.'
: '' : ''

View File

@@ -9,7 +9,10 @@ module.exports = class UpdateAvailableModal extends React.Component {
return ( return (
<div className='update-available-modal'> <div className='update-available-modal'>
<p><strong>A new version of WebTorrent is available: v{state.modal.version}</strong></p> <p><strong>A new version of WebTorrent is available: v{state.modal.version}</strong></p>
<p>We have an auto-updater for Windows and Mac. We don't have one for Linux yet, so you'll have to download the new version manually.</p> <p>
We have an auto-updater for Windows and Mac.
We don't have one for Linux yet, so you'll have to download the new version manually.
</p>
<p className='float-right'> <p className='float-right'>
<button className='button button-flat' onClick={handleSkip}>Skip This Release</button> <button className='button button-flat' onClick={handleSkip}>Skip This Release</button>
<button className='button button-raised' onClick={handleShow}>Show Download Page</button> <button className='button button-raised' onClick={handleShow}>Show Download Page</button>

View File

@@ -47,7 +47,10 @@ module.exports = class MediaController {
openExternalPlayer () { openExternalPlayer () {
var state = this.state var state = this.state
var mediaURL = Playlist.getCurrentLocalURL(this.state) var mediaURL = Playlist.getCurrentLocalURL(this.state)
ipcRenderer.send('openExternalPlayer', state.saved.prefs.externalPlayerPath, mediaURL, state.window.title) ipcRenderer.send('openExternalPlayer',
state.saved.prefs.externalPlayerPath,
mediaURL,
state.window.title)
state.playing.location = 'external' state.playing.location = 'external'
} }

View File

@@ -148,13 +148,16 @@ module.exports = class PlaybackController {
rate += 0.25 rate += 0.25
} else if (direction < 0 && rate > 0.25 && rate <= 2) { } else if (direction < 0 && rate > 0.25 && rate <= 2) {
rate -= 0.25 rate -= 0.25
} else if (direction < 0 && rate === 0.25) { /* when we set playback rate at 0 in html 5, playback hangs ;( */ } else if (direction < 0 && rate === 0.25) {
// When we set playback rate at 0 in html 5, playback hangs ;(
rate = -1 rate = -1
} else if (direction > 0 && rate === -1) { } else if (direction > 0 && rate === -1) {
rate = 0.25 rate = 0.25
} else if ((direction > 0 && rate >= 1 && rate < 16) || (direction < 0 && rate > -16 && rate <= -1)) { } else if ((direction > 0 && rate >= 1 && rate < 16) ||
(direction < 0 && rate > -16 && rate <= -1)) {
rate *= 2 rate *= 2
} else if ((direction < 0 && rate > 1 && rate <= 16) || (direction > 0 && rate >= -16 && rate < -1)) { } else if ((direction < 0 && rate > 1 && rate <= 16) ||
(direction > 0 && rate >= -16 && rate < -1)) {
rate /= 2 rate /= 2
} }
state.playing.playbackRate = rate state.playing.playbackRate = rate
@@ -342,7 +345,7 @@ module.exports = class PlaybackController {
var result = state.playing.result // 'success' or 'error' var result = state.playing.result // 'success' or 'error'
if (result === 'success') telemetry.logPlayAttempt('success') // first frame displayed if (result === 'success') telemetry.logPlayAttempt('success') // first frame displayed
else if (result === 'error') telemetry.logPlayAttempt('error') // codec missing, etc else if (result === 'error') telemetry.logPlayAttempt('error') // codec missing, etc
else if (result === undefined) telemetry.logPlayAttempt('abandoned') // user exited before first frame else if (result === undefined) telemetry.logPlayAttempt('abandoned') // user gave up waiting
else console.error('Unknown state.playing.result', state.playing.result) else console.error('Unknown state.playing.result', state.playing.result)
// Reset the window contents back to the home screen // Reset the window contents back to the home screen

View File

@@ -17,8 +17,8 @@ module.exports = class TorrentListController {
this.state = state this.state = state
} }
// Adds a torrent to the list, starts downloading/seeding. TorrentID can be a // Adds a torrent to the list, starts downloading/seeding.
// magnet URI, infohash, or torrent file: https://github.com/feross/webtorrent#clientaddtorrentid-opts-function-ontorrent-torrent- // TorrentID can be a magnet URI, infohash, or torrent file: https://git.io/vik9M
addTorrent (torrentId) { addTorrent (torrentId) {
if (torrentId.path) { if (torrentId.path) {
// Use path string instead of W3C File object // Use path string instead of W3C File object
@@ -149,7 +149,7 @@ module.exports = class TorrentListController {
// remove torrent and poster file // remove torrent and poster file
deleteFile(TorrentSummary.getTorrentPath(summary)) deleteFile(TorrentSummary.getTorrentPath(summary))
deleteFile(TorrentSummary.getPosterPath(summary)) // TODO: will the css path hack affect windows? deleteFile(TorrentSummary.getPosterPath(summary))
// optionally delete the torrent data // optionally delete the torrent data
if (deleteData) moveItemToTrash(summary) if (deleteData) moveItemToTrash(summary)
@@ -159,7 +159,8 @@ module.exports = class TorrentListController {
State.saveThrottled(this.state) State.saveThrottled(this.state)
} }
this.state.location.clearForward('player') // prevent user from going forward to a deleted torrent // prevent user from going forward to a deleted torrent
this.state.location.clearForward('player')
sound.play('DELETE') sound.play('DELETE')
} }
@@ -288,7 +289,8 @@ function saveTorrentFileAs (torrentSummary) {
{ name: 'All Files', extensions: ['*'] } { name: 'All Files', extensions: ['*'] }
] ]
} }
electron.remote.dialog.showSaveDialog(electron.remote.getCurrentWindow(), opts, function (savePath) { var win = electron.remote.getCurrentWindow()
electron.remote.dialog.showSaveDialog(win, opts, function (savePath) {
if (!savePath) return // They clicked Cancel if (!savePath) return // They clicked Cancel
var torrentPath = TorrentSummary.getTorrentPath(torrentSummary) var torrentPath = TorrentSummary.getTorrentPath(torrentSummary)
fs.readFile(torrentPath, function (err, torrentFile) { fs.readFile(torrentPath, function (err, torrentFile) {

View File

@@ -350,7 +350,8 @@ function toggleMenu (location) {
// Never cast to two devices at the same time // Never cast to two devices at the same time
if (state.playing.location !== 'local') { if (state.playing.location !== 'local') {
throw new Error('You can\'t connect to ' + location + ' when already connected to another device') throw new Error('You can\'t connect to ' + location +
' when already connected to another device')
} }
// Find all cast devices of the given type // Find all cast devices of the given type

View File

@@ -179,12 +179,18 @@ const dispatchHandlers = {
'showCreateTorrent': (paths) => controllers.torrentList.showCreateTorrent(paths), 'showCreateTorrent': (paths) => controllers.torrentList.showCreateTorrent(paths),
'createTorrent': (options) => controllers.torrentList.createTorrent(options), 'createTorrent': (options) => controllers.torrentList.createTorrent(options),
'toggleTorrent': (infoHash) => controllers.torrentList.toggleTorrent(infoHash), 'toggleTorrent': (infoHash) => controllers.torrentList.toggleTorrent(infoHash),
'toggleTorrentFile': (infoHash, index) => controllers.torrentList.toggleTorrentFile(infoHash, index), 'toggleTorrentFile': (infoHash, index) =>
'confirmDeleteTorrent': (infoHash, deleteData) => controllers.torrentList.confirmDeleteTorrent(infoHash, deleteData), controllers.torrentList.toggleTorrentFile(infoHash, index),
'deleteTorrent': (infoHash, deleteData) => controllers.torrentList.deleteTorrent(infoHash, deleteData), 'confirmDeleteTorrent': (infoHash, deleteData) =>
'toggleSelectTorrent': (infoHash) => controllers.torrentList.toggleSelectTorrent(infoHash), controllers.torrentList.confirmDeleteTorrent(infoHash, deleteData),
'openTorrentContextMenu': (infoHash) => controllers.torrentList.openTorrentContextMenu(infoHash), 'deleteTorrent': (infoHash, deleteData) =>
'startTorrentingSummary': (torrentKey) => controllers.torrentList.startTorrentingSummary(torrentKey), controllers.torrentList.deleteTorrent(infoHash, deleteData),
'toggleSelectTorrent': (infoHash) =>
controllers.torrentList.toggleSelectTorrent(infoHash),
'openTorrentContextMenu': (infoHash) =>
controllers.torrentList.openTorrentContextMenu(infoHash),
'startTorrentingSummary': (torrentKey) =>
controllers.torrentList.startTorrentingSummary(torrentKey),
// Playback // Playback
'playFile': (infoHash, index) => controllers.playback.playFile(infoHash, index), 'playFile': (infoHash, index) => controllers.playback.playFile(infoHash, index),

View File

@@ -100,8 +100,8 @@ function init () {
console.timeEnd('init') console.timeEnd('init')
} }
// Starts a given TorrentID, which can be an infohash, magnet URI, etc. Returns WebTorrent object // Starts a given TorrentID, which can be an infohash, magnet URI, etc.
// See https://github.com/feross/webtorrent/blob/master/docs/api.md#clientaddtorrentid-opts-function-ontorrent-torrent- // Returns a WebTorrent object. See https://git.io/vik9M
function startTorrenting (torrentKey, torrentID, path, fileModtimes, selections) { function startTorrenting (torrentKey, torrentID, path, fileModtimes, selections) {
console.log('starting torrent %s: %s', torrentKey, torrentID) console.log('starting torrent %s: %s', torrentKey, torrentID)