Skip to content

Commit

Permalink
Implement standard for JS linting (#354)
Browse files Browse the repository at this point in the history
use standard JS
  • Loading branch information
singingwolfboy committed Feb 15, 2017
1 parent 9782992 commit 33972ed
Show file tree
Hide file tree
Showing 46 changed files with 1,929 additions and 1,751 deletions.
1 change: 1 addition & 0 deletions Makefile
Expand Up @@ -26,6 +26,7 @@ coverage-python: test-python

test-js: build-js
@echo "---> running javascript tests"
@cd lektor/admin; npm run lint
@cd lektor/admin; npm test

coverage-js: test-js
Expand Down
2 changes: 1 addition & 1 deletion gui/static/js/app.jsx
Expand Up @@ -106,7 +106,7 @@ class App extends Component {
let projectPath = this.state.projectData
? this.state.projectData.project_path : null

function couldNotOpen(message) {
const couldNotOpen = (message) => {
dialog.showErrorBox(i18n.trans('FAILED_TO_OPEN_CONTENT_FILE'),
message.toString())
}
Expand Down
6 changes: 3 additions & 3 deletions gui/static/js/host.jsx
Expand Up @@ -8,7 +8,7 @@ import i18n from './i18n'
const BASE_PATH = __dirname.match(/^(.*?)[\/\\][^\/\\]+$/)[1]


function initWindow() {
const initWindow = () => {
let loadedOnce = false;
let win = new BrowserWindow({
width: 400,
Expand Down Expand Up @@ -38,7 +38,7 @@ function initWindow() {
return win;
}

function initAppIcon(win) {
const initAppIcon=(win) =>{
let appIcon = new Tray(BASE_PATH + '/images/TrayTemplate.png');

appIcon.on('clicked', (e, bounds) => {
Expand All @@ -52,7 +52,7 @@ function initAppIcon(win) {
appIcon.setToolTip('Lektor');
}

function main() {
const main = () => {
let filesToOpen = [];
let win = null;
let appIcon = null;
Expand Down
20 changes: 10 additions & 10 deletions gui/static/js/lektorInterop.jsx
Expand Up @@ -8,16 +8,16 @@ import i18n from './i18n'
const app = remote.require('app')
const dialog = remote.require('dialog')

function getResourceFolder () {
const getResourceFolder = () => {
// XXX: windows support
return path.dirname(app.getAppPath());
}

function getBundleBase () {
const getBundleBase = () => {
return path.dirname(getResourceFolder())
}

function findBundledLektorExecutable () {
const findBundledLektorExecutable = () => {
let res = getResourceFolder()
try {
if (process.platform === 'darwin') {
Expand All @@ -33,7 +33,7 @@ function findBundledLektorExecutable () {
return null
}

function findGlobalLektorExecutable () {
const findGlobalLektorExecutable = () => {
let rv
if (process.platform === 'win32') {
rv = childProcess.spawnSync('where.exe', ['lektor'])
Expand All @@ -46,19 +46,19 @@ function findGlobalLektorExecutable () {
return null
}

export function findLektorExecutable () {
export const findLektorExecutable = () => {
return findBundledLektorExecutable() || findGlobalLektorExecutable()
}

export function findLektorProxyExecutable () {
export const findLektorProxyExecutable = () => {
if (process.platform == 'darwin') {
return path.join(getBundleBase(), 'Resources', 'local', 'bin', 'lektor-proxy')
} else {
return findLektorExecutable()
}
}

export function installShellCommands () {
export const installShellCommands = () => {
let runas = require('runas')
let exe = findLektorProxyExecutable()
let rv = runas(exe, ['--install-shell-command'], {
Expand All @@ -76,7 +76,7 @@ class LektorServer {
this._statusLineCallback = options.statusLineCallback

child.stdout.on('data', (data) => {
var lines = (data + '').split(/\r?\n/)
const lines = (data + '').split(/\r?\n/)
lines.forEach((line) => {
this._statusLineCallback(line.trimRight())
})
Expand Down Expand Up @@ -105,8 +105,8 @@ class LektorServer {
}
}

function spawnLektor (exe, args) {
var env = {}
const spawnLektor = (exe, args) => {
let env = {}
Object.keys(process.env).forEach((key) => {
env[key] = process.env[key]
})
Expand Down
4 changes: 2 additions & 2 deletions gui/static/js/utils.jsx
@@ -1,10 +1,10 @@
'use strict'

export function isDevMode() {
export const isDevMode = () => {
return process.env.LEKTOR_DEV === '1'
}

export function attachDevMenu(menu) {
export const attachDevMenu = (menu) => {
menu.push({
label: 'Reload',
accelerator: 'CmdOrCtrl+R',
Expand Down
16 changes: 14 additions & 2 deletions lektor/admin/package.json
Expand Up @@ -34,11 +34,13 @@
"react-addons-update": "^15.3.0",
"react-dom": "^15.3.0",
"react-router": "^2.6.0",
"standard": ">8.5.0",
"style-loader": "^0.8.3",
"url-loader": "^0.5.6",
"webpack": "^1.7.2"
},
"scripts": {
"lint": "standard",
"test": "nyc mocha static/js/**/*.test.js",
"report-coverage": "nyc report --reporter=lcov > coverage.lcov",
"webpack": "webpack --config ./static/webpack.config.js --context ./static"
Expand All @@ -60,8 +62,18 @@
}
},
"nyc": {
"extension": [".jsx"],
"require": ["babel-register"]
"extension": [
".jsx"
],
"require": [
"babel-register"
]
},
"standard": {
"ignore": [
"static/gen/"
],
"globals": ["$LEKTOR_CONFIG"]
},
"author": "",
"license": "ISC"
Expand Down
18 changes: 10 additions & 8 deletions lektor/admin/static/js/bootstrap-extras.jsx
@@ -1,8 +1,10 @@
$(document).ready(function() {
$('[data-toggle=offcanvas]').click(function() {
var target = $($(this).attr('data-target') || '.block-offcanvas');
var isActive = target.is('.active');
target.toggleClass('active', !isActive);
$(this).toggleClass('active', !isActive);
});
});
import $ from 'jquery'

$(document).ready(() => {
$('[data-toggle=offcanvas]').click(() => {
const target = $($(this).attr('data-target') || '.block-offcanvas')
const isActive = target.is('.active')
target.toggleClass('active', !isActive)
$(this).toggleClass('active', !isActive)
})
})
15 changes: 6 additions & 9 deletions lektor/admin/static/js/components/BaseComponent.jsx
Expand Up @@ -5,23 +5,20 @@

'use strict'

import React from 'react';

import React from 'react'

class BaseComponent extends React.Component {

componentDidMount() {
componentDidMount () {
}

componentWillUnmount() {
componentWillUnmount () {
}

componentDidUpdate() {
componentDidUpdate () {
}

componentWillReceiveProps(nextProps) {
componentWillReceiveProps (nextProps) {
}

}

export default BaseComponent;
export default BaseComponent

0 comments on commit 33972ed

Please sign in to comment.