Skip to content

Commit

Permalink
Fix linter issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
obuchtala committed Mar 13, 2017
1 parent dfc7cd4 commit 795c7f0
Show file tree
Hide file tree
Showing 20 changed files with 102 additions and 94 deletions.
2 changes: 1 addition & 1 deletion index.es.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ export { sheetConversion }

export { default as functions } from './src/functions'
export { default as type } from './src/functions/types/type'
export { default as JsContext } from './src/js-context/JsContext'
export { default as JsContext } from './src/js-context/JsContext'
export { address, value }
8 changes: 5 additions & 3 deletions src/document/CellEngine.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class CellEngine extends Engine {
this._cells = {}
this._contexts = editorSession.getContext().stencilaContexts || {}

console.log('INITIALIZING CELL ENGINE')
// console.log('INITIALIZING CELL ENGINE')
this._initialize()

editorSession.on('render', this._onDocumentChange, this, {
Expand Down Expand Up @@ -70,10 +70,11 @@ class CellEngine extends Engine {
}
// chunks
case 'run': {

// TODO
break
}
// all others are external functions
default:
default: {
// regular function calls: we need to lookup
const func = this._lookupFunction(functionName)
if (func) {
Expand All @@ -89,6 +90,7 @@ class CellEngine extends Engine {
} else {
return Promise.reject(`Could not resolve function "${functionName}"`)
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/document/nodes/codeblock/CodeblockHTMLConverter.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default {
return false
},

import: function (el, node, converter) {
import: function (el, node) {
node.language = el.attr('class') || 'text'
var code = el.find('code')
node.source = code.text().trim()
Expand Down
49 changes: 25 additions & 24 deletions src/document/nodes/codeblock/CodeblockTool.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,31 @@ import BlockTool from '../../ui/BlockTool'
class CodeblockTool extends BlockTool {

render ($$) {
var node = this.props.node
return super.render.call(this, $$)
.addClass('sc-codeblock-tool')
.append(
$$('div')
.ref('details')
.addClass('se-details')
.append(
$$('input')
.ref('language')
.attr({
placeholder: 'Enter the code language',
spellcheck: 'false'
})
.val(node.language)
.on('change', function (event) {
var session = this.context.documentSession
session.transaction(function (tx, args) {
tx.set([node.id, 'language'], event.target.value)
})
}.bind(this))
)
)
const node = this.props.node
const el = super.render($$)
el.addClass('sc-codeblock-tool')

const details = $$('div').ref('details').addClass('se-details')
details.append(
$$('input').ref('language')
.attr({
placeholder: 'Enter the code language',
spellcheck: 'false'
})
.val(node.language)
.on('change', this.onLanguageChange)
)
el.append(details)
return el
}

onLanguageChange(event) {
const node = this.props.node
const session = this.context.editorSession
session.transaction((tx) => {
tx.set([node.id, 'language'], event.target.value)
})
}
}

export default CodeblockTool
export default CodeblockTool
44 changes: 23 additions & 21 deletions src/document/nodes/default/DefaultTool.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,29 @@ import BlockTool from '../../ui/BlockTool'
class DefaultTool extends BlockTool {

render ($$) {
var node = this.props.node
return super.render.call(this, $$)
.addClass('sc-default-tool')
.append(
$$('div')
.ref('details')
.addClass('se-details')
.append(
$$('button')
.ref('edit')
.addClass('se-edit')
.attr('title', 'Edit')
.append(
$$('i')
.addClass('fa fa-pencil')
)
.on('click', function (event) {
node.emit('edit:toggle')
})
)
)
const el = super.render($$)
el.addClass('sc-default-tool')

const detail = $$('div').ref('details').addClass('se-details')
detail.append(
$$('button').ref('edit')
.addClass('se-edit')
.attr('title', 'Edit')
.append(
$$('i')
.addClass('fa fa-pencil')
)
.on('click', this.onEditClick)
)
el.append(detail)
return el
}

onEditClick(event) {
event.preventDefault()
event.stopPropagation()
const node = this.props.node
node.emit('edit:toggle')
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/document/nodes/include/IncludeHTMLConverter.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ export default {
return el.is('[data-include]')
},

import: function (el, node, converter) {
import: function (el, node) {
node.address = el.attr('data-include')
node.selector = el.attr('data-selector') || ''
node.input = el.attr('data-input') || ''
},

export: function (node, el, converter) {
export: function (node, el) {
el.attr('data-include', node.address)
if (node.selector) el.attr('data-selector', node.selector)
if (node.input) el.attr('data-input', node.input)
Expand Down
2 changes: 1 addition & 1 deletion src/document/nodes/link/LinkMacro.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import AnnotationMacro from '../../ui/AnnotationMacro'
class LinkMacro extends AnnotationMacro {

get regex () {
return /\[([^\]]+)\]\(([^\)]+)\)/
return /\[([^\]]+)\]\(([^)]+)\)/
}

createNodeData (match) {
Expand Down
2 changes: 1 addition & 1 deletion src/document/nodes/strong/StrongMacro.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import AnnotationMacro from '../../ui/AnnotationMacro'
class StrongMacro extends AnnotationMacro {

get regex () {
return /\*([^\*]+)\*/
return /\*([^*]+)\*/
}

createNodeData (match) {
Expand Down
36 changes: 19 additions & 17 deletions src/document/ui/InlineNodeMacro.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
/* eslint-disable no-unused-vars */
import { Editing } from 'substance'
import Macro from './Macro'

class InlineNodeMacro extends Macro {

performAction (match, props, context) {
var surface = context.surfaceManager.getSurface(props.selection.surfaceId)
surface.transaction(function (tx, args) {
var sel = tx.createSelection(props.path, match.index, match.index + match[0].length)
// Insert a new node (there is no need to delete the matched text, that is
// done for us)
let editing = new Editing()
editing.insertInlineNode(tx, {
selection: sel,
node: this.createNodeData(match)
})
if (props.action === 'type') {
// Move caret to just after the newly inserted node
return {
selection: tx.createSelection(props.path, match.index + 1)
}
}
}.bind(this))
// FIXME: this needs to ported to latest substance
// var surface = context.surfaceManager.getSurface(props.selection.surfaceId)
// surface.transaction(function (tx) {
// var sel = tx.createSelection(props.path, match.index, match.index + match[0].length)
// // Insert a new node (there is no need to delete the matched text, that is
// // done for us)
// let editing = new Editing()
// editing.insertInlineNode(tx, {
// selection: sel,
// node: this.createNodeData(match)
// })
// if (props.action === 'type') {
// // Move caret to just after the newly inserted node
// return {
// selection: tx.createSelection(props.path, match.index + 1)
// }
// }
// }.bind(this))
}

}
Expand Down
4 changes: 2 additions & 2 deletions src/document/ui/Macro.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Macro {
*
* @param {<type>} match The match
*/
performAction (match, props, context) {
performAction (match, props, context) { // eslint-disable-line no-unused-vars
throw new Error('This method is abstract.')
}

Expand All @@ -40,7 +40,7 @@ class Macro {
*
* @param {<type>} match The match
*/
createNodeData (match) {
createNodeData (match) { // eslint-disable-line no-unused-vars
throw new Error('This method is abstract.')
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/functions/formats/csv.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as d3 from 'd3'
export default function csv (content) {
return d3.csvParse(content).map(row => {
let converted = {}
for (let field in row) {
for (let field in row) { // eslint-disable-line guard-for-in
let str = row[field]
let flt = parseFloat(str)
converted[field] = isNaN(flt) ? str : flt
Expand Down
6 changes: 3 additions & 3 deletions src/js-context/JsContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default class JsContext {
let last = lines[lines.length - 1]
try {
value = (new Function('return ' + last))() // eslint-disable-line no-new-func
} catch (error) {
} catch (err) {
value = undefined
}
}
Expand Down Expand Up @@ -136,7 +136,7 @@ export default class JsContext {
}
}, base)
let depends = []
for (let name in names) {
for (let name in names) { // eslint-disable-line guard-for-in
let usage = names[name]
if (usage.used && !usage.declared) depends.push(name)
}
Expand All @@ -162,7 +162,7 @@ export default class JsContext {
let message = lines[0]
let match = lines[1].match(/<anonymous>:(\d+):\d+/)
let line = 0
if (match) line = parseInt(match[1]) - 1 - offset
if (match) line = parseInt(match[1], 10) - 1 - offset
errors = {}
errors[line] = message
}
Expand Down
3 changes: 0 additions & 3 deletions src/sheet/model/SheetCellHTMLConverter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import SheetCell from './SheetCell'
import { kindToSymbol } from './sheetHelpers'

export default {

type: 'sheet-cell',
Expand Down
2 changes: 1 addition & 1 deletion src/sheet/model/SheetDocument.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Document, forEach } from 'substance'
import { Document } from 'substance'

/*
A SheetDocument is a document with a number of sheets.
Expand Down
2 changes: 1 addition & 1 deletion src/sheet/ui/CellTeaserComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class CellTeaserComponent extends Component {
let name = cell.getName()
if (name) {
tr.append(
$$('td').addClass('se-name').text(prefix)
$$('td').addClass('se-name').text(name)
)
}
let value = cell.value
Expand Down
3 changes: 2 additions & 1 deletion src/sheet/ui/HTMLCellComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ export default
class HTMLCellComponent extends Component {

render($$) {
const cell = this.props.node
const node = this.props.node
const value = node.value
const el = $$('div').addClass('sc-html-cell')
if (value === undefined) {
el.addClass('sm-loading')
Expand Down
9 changes: 6 additions & 3 deletions src/sheet/ui/SheetComponent.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import {Component, DefaultDOMElement, inBrowser, uuid, findParentComponent, TextInput} from 'substance'
import {
Component, DefaultDOMElement,
inBrowser, uuid, findParentComponent
} from 'substance'
import {getColumnName} from '../model/sheetHelpers'
import SheetEngine from '../model/SheetEngine'
import SheetCellComponent from './SheetCellComponent'
Expand Down Expand Up @@ -374,11 +377,11 @@ class SheetComponent extends Component {
}

onConfirmExpression() {
console.log('Confirmed expression change')
console.info('Confirmed expression change')
}

onCancelExpression() {
console.log('Canceled expression change')
console.info('Canceled expression change')
}

// private API
Expand Down
12 changes: 6 additions & 6 deletions src/utilities/code/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// ATTENTION: this is actually importing a bundled version of brace
import brace from 'brace'

var attachAceEditor = function (el, content, options, callback) {
function attachAceEditor(el, content, options, callback) {
var editor = brace.edit(el)
updateAceEditor(editor, options)
if (content) editor.setValue(content, 1)
if (callback) callback(editor)
}

var setAceEditorMode = function (editor, language) {
function setAceEditorMode(editor, language) {
// Convert language tag to ACE mode if necessary
// If no language defined, default to plain text
// If no conversion defined here will use mode = language
Expand All @@ -25,7 +25,7 @@ var setAceEditorMode = function (editor, language) {
editor.getSession().setMode('ace/mode/' + mode)
}

var updateAceEditor = function (editor, options) {
function updateAceEditor(editor, options) {
options = options || {}

// Stuff that is not yet actually an option
Expand Down Expand Up @@ -73,7 +73,7 @@ var updateAceEditor = function (editor, options) {
}

export default {
attachAceEditor: attachAceEditor,
setAceEditorMode: setAceEditorMode,
updateAceEditor: updateAceEditor
attachAceEditor,
setAceEditorMode,
updateAceEditor
}
2 changes: 1 addition & 1 deletion src/utilities/location.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function params () {
var tokens
var re = /[?&]?([^=]+)=([^&]*)/g

while (true) {
while (true) { // eslint-disable-line no-constant-condition
tokens = re.exec(qs)
if (!tokens) break
params[decodeURIComponent(tokens[1])] = decodeURIComponent(tokens[2])
Expand Down
2 changes: 1 addition & 1 deletion src/value.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export function unpack (pkg) {
} else if (type === 'bool') {
return content === 'true'
} else if (type === 'int') {
return parseInt(content)
return parseInt(content, 10)
} else if (type === 'flt') {
return parseFloat(content)
} else if (type === 'str') {
Expand Down

0 comments on commit 795c7f0

Please sign in to comment.