Set eslint no-inline-comments

This commit is contained in:
Rob Garrison 2017-08-20 13:56:18 -05:00
parent 5936d766f8
commit 3e371f193a
3 changed files with 53 additions and 26 deletions

View File

@ -151,7 +151,7 @@ rules:
no-implicit-coercion: [1] no-implicit-coercion: [1]
no-implicit-globals: [0] no-implicit-globals: [0]
no-implied-eval: [2] no-implied-eval: [2]
no-inline-comments: [0] no-inline-comments: [2]
no-inner-declarations: [2] no-inner-declarations: [2]
no-invalid-regexp: [2] no-invalid-regexp: [2]
no-invalid-this: [0] no-invalid-this: [0]

View File

@ -5,10 +5,13 @@
'use strict'; 'use strict';
let styleId = null; let styleId = null;
let dirty = {}; // only the actually dirty items here // only the actually dirty items here
const editors = []; // array of all CodeMirror instances let dirty = {};
// array of all CodeMirror instances
const editors = [];
let saveSizeOnClose; let saveSizeOnClose;
let useHistoryBack; // use browser history back when 'back to manage' is clicked // use browser history back when 'back to manage' is clicked
let useHistoryBack;
// direct & reverse mapping of @-moz-document keywords and internal property names // direct & reverse mapping of @-moz-document keywords and internal property names
const propertyToCss = {urls: 'url', urlPrefixes: 'url-prefix', domains: 'domain', regexps: 'regexp'}; const propertyToCss = {urls: 'url', urlPrefixes: 'url-prefix', domains: 'domain', regexps: 'regexp'};
@ -34,7 +37,8 @@ Element.prototype.closest = Element.prototype.closest || function (selector) {
}; };
// eslint-disable-next-line no-extend-native // eslint-disable-next-line no-extend-native
Array.prototype.rotate = function (amount) { // negative amount == rotate left Array.prototype.rotate = function (amount) {
// negative amount == rotate left
const r = this.slice(-amount, this.length); const r = this.slice(-amount, this.length);
Array.prototype.push.apply(r, this.slice(0, this.length - r.length)); Array.prototype.push.apply(r, this.slice(0, this.length - r.length));
return r; return r;
@ -93,7 +97,8 @@ function onChange(event) {
} else { } else {
// the manually added section's applies-to is dirty only when the value is non-empty // the manually added section's applies-to is dirty only when the value is non-empty
setCleanItem(node, node.localName !== 'input' || !node.value.trim()); setCleanItem(node, node.localName !== 'input' || !node.value.trim());
delete node.savedValue; // only valid when actually saved // only valid when actually saved
delete node.savedValue;
} }
updateTitle(); updateTitle();
} }
@ -137,7 +142,8 @@ function isCleanGlobal() {
function setCleanGlobal() { function setCleanGlobal() {
document.querySelectorAll('#header, #sections > div').forEach(setCleanSection); document.querySelectorAll('#header, #sections > div').forEach(setCleanSection);
dirty = {}; // forget the dirty applies-to ids from a deleted section after the style was saved // forget the dirty applies-to ids from a deleted section after the style was saved
dirty = {};
} }
function setCleanSection(section) { function setCleanSection(section) {
@ -178,7 +184,8 @@ function initCodeMirror() {
styleActiveLine: true, styleActiveLine: true,
theme: 'default', theme: 'default',
keyMap: prefs.get('editor.keyMap'), keyMap: prefs.get('editor.keyMap'),
extraKeys: { // independent of current keyMap extraKeys: {
// independent of current keyMap
'Alt-Enter': 'toggleStyle', 'Alt-Enter': 'toggleStyle',
'Alt-PageDown': 'nextEditor', 'Alt-PageDown': 'nextEditor',
'Alt-PageUp': 'prevEditor' 'Alt-PageUp': 'prevEditor'
@ -208,9 +215,12 @@ function initCodeMirror() {
CM.keyMap.macDefault['Cmd-J'] = 'jumpToLine'; CM.keyMap.macDefault['Cmd-J'] = 'jumpToLine';
} }
if (!extraKeysCommands.autocomplete) { if (!extraKeysCommands.autocomplete) {
CM.keyMap.pcDefault['Ctrl-Space'] = 'autocomplete'; // will be used by 'sublime' on PC via fallthrough // will be used by 'sublime' on PC via fallthrough
CM.keyMap.macDefault['Alt-Space'] = 'autocomplete'; // OSX uses Ctrl-Space and Cmd-Space for something else CM.keyMap.pcDefault['Ctrl-Space'] = 'autocomplete';
CM.keyMap.emacsy['Alt-/'] = 'autocomplete'; // copied from 'emacs' keymap // OSX uses Ctrl-Space and Cmd-Space for something else
CM.keyMap.macDefault['Alt-Space'] = 'autocomplete';
// copied from 'emacs' keymap
CM.keyMap.emacsy['Alt-/'] = 'autocomplete';
// 'vim' and 'emacs' define their own autocomplete hotkeys // 'vim' and 'emacs' define their own autocomplete hotkeys
} }
if (!extraKeysCommands.blockComment) { if (!extraKeysCommands.blockComment) {
@ -228,8 +238,10 @@ function initCodeMirror() {
// try to remap non-interceptable Ctrl-(Shift-)N/T/W hotkeys // try to remap non-interceptable Ctrl-(Shift-)N/T/W hotkeys
['N', 'T', 'W'].forEach(char => { ['N', 'T', 'W'].forEach(char => {
[{from: 'Ctrl-', to: ['Alt-', 'Ctrl-Alt-']}, [
{from: 'Shift-Ctrl-', to: ['Ctrl-Alt-', 'Shift-Ctrl-Alt-']} // Note: modifier order in CM is S-C-A {from: 'Ctrl-', to: ['Alt-', 'Ctrl-Alt-']},
// Note: modifier order in CM is S-C-A
{from: 'Shift-Ctrl-', to: ['Ctrl-Alt-', 'Shift-Ctrl-Alt-']}
].forEach(remap => { ].forEach(remap => {
const oldKey = remap.from + char; const oldKey = remap.from + char;
Object.keys(CM.keyMap).forEach(keyMapName => { Object.keys(CM.keyMap).forEach(keyMapName => {
@ -319,7 +331,8 @@ function acmeEventListener(event) {
break; break;
} }
const url = chrome.runtime.getURL('vendor/codemirror/theme/' + value + '.css'); const url = chrome.runtime.getURL('vendor/codemirror/theme/' + value + '.css');
if (themeLink.href === url) { // preloaded in initCodeMirror() if (themeLink.href === url) {
// preloaded in initCodeMirror()
break; break;
} }
// avoid flicker: wait for the second stylesheet to load, then apply the theme // avoid flicker: wait for the second stylesheet to load, then apply the theme
@ -400,8 +413,10 @@ function setupCodeMirror(textarea, index) {
} }
lastClickTime = Date.now(); lastClickTime = Date.now();
const minHeight = cm.defaultTextHeight() + const minHeight = cm.defaultTextHeight() +
cm.display.lineDiv.offsetParent.offsetTop + /* .CodeMirror-lines padding */ /* .CodeMirror-lines padding */
wrapper.offsetHeight - wrapper.clientHeight; /* borders */ cm.display.lineDiv.offsetParent.offsetTop +
/* borders */
wrapper.offsetHeight - wrapper.clientHeight;
wrapper.style.pointerEvents = 'none'; wrapper.style.pointerEvents = 'none';
document.body.style.cursor = 's-resize'; document.body.style.cursor = 's-resize';
function resize(e) { function resize(e) {
@ -715,9 +730,11 @@ function setupGlobalSearch() {
const originalOpenDialog = CodeMirror.prototype.openDialog; const originalOpenDialog = CodeMirror.prototype.openDialog;
const originalOpenConfirm = CodeMirror.prototype.openConfirm; const originalOpenConfirm = CodeMirror.prototype.openConfirm;
let curState; // cm.state.search for last used 'find' // cm.state.search for last used 'find'
let curState;
function shouldIgnoreCase(query) { // treat all-lowercase non-regexp queries as case-insensitive function shouldIgnoreCase(query) {
// treat all-lowercase non-regexp queries as case-insensitive
return typeof query === 'string' && query === query.toLowerCase(); return typeof query === 'string' && query === query.toLowerCase();
} }
@ -787,7 +804,8 @@ function setupGlobalSearch() {
return; return;
} }
let pos = activeCM.getCursor(reverse ? 'from' : 'to'); let pos = activeCM.getCursor(reverse ? 'from' : 'to');
activeCM.setSelection(activeCM.getCursor()); // clear the selection, don't move the cursor // clear the selection, don't move the cursor
activeCM.setSelection(activeCM.getCursor());
const rxQuery = typeof state.query === 'object' const rxQuery = typeof state.query === 'object'
? state.query : stringAsRegExp(state.query, shouldIgnoreCase(state.query) ? 'i' : ''); ? state.query : stringAsRegExp(state.query, shouldIgnoreCase(state.query) ? 'i' : '');
@ -1045,7 +1063,8 @@ function getEditorInSight(nearbyElement) {
return cm; return cm;
function offscreenDistance(cm) { function offscreenDistance(cm) {
const LINES_VISIBLE = 2; // closest editor should have at least # lines visible // closest editor should have at least # lines visible
const LINES_VISIBLE = 2;
const bounds = cm.getSection().getBoundingClientRect(); const bounds = cm.getSection().getBoundingClientRect();
if (bounds.top < 0) { if (bounds.top < 0) {
return -bounds.top; return -bounds.top;
@ -1149,7 +1168,8 @@ document.addEventListener('DOMContentLoaded', init);
function init() { function init() {
initCodeMirror(); initCodeMirror();
const params = getParams(); const params = getParams();
if (!params.id) { // match should be 2 - one for the whole thing, one for the parentheses if (!params.id) {
// match should be 2 - one for the whole thing, one for the parentheses
// This is an add // This is an add
$('#heading').textContent = t('addStyleTitle'); $('#heading').textContent = t('addStyleTitle');
const section = {code: ''}; const section = {code: ''};
@ -1593,8 +1613,12 @@ function fromMozillaFormat() {
// do onetime housekeeping as the imported text is confirmed to be a valid style // do onetime housekeeping as the imported text is confirmed to be a valid style
function initFirstSection(section) { function initFirstSection(section) {
// skip adding the first global section when there's no code/comments // skip adding the first global section when there's no code/comments
if (!section.code.replace('@namespace url(http://www.w3.org/1999/xhtml);', '') /* ignore boilerplate NS */ if (
.replace(/[\s\n]/g, '')) { /* ignore all whitespace including new lines */ /* ignore boilerplate NS */
!section.code.replace('@namespace url(http://www.w3.org/1999/xhtml);', '')
/* ignore all whitespace including new lines */
.replace(/[\s\n]/g, '')
) {
return false; return false;
} }
if (replaceOldStyle) { if (replaceOldStyle) {
@ -1889,7 +1913,8 @@ function showHelp(title, body) {
if (getComputedStyle(div).display === 'none') { if (getComputedStyle(div).display === 'none') {
document.addEventListener('keydown', closeHelp); document.addEventListener('keydown', closeHelp);
div.querySelector('.dismiss').onclick = closeHelp; // avoid chaining on multiple showHelp() calls // avoid chaining on multiple showHelp() calls
div.querySelector('.dismiss').onclick = closeHelp;
} }
div.style.display = 'block'; div.style.display = 'block';

View File

@ -37,7 +37,8 @@ function updateLinter(name) {
editors.forEach(cm => { editors.forEach(cm => {
// set lint to "null" to disable // set lint to "null" to disable
cm.setOption('lint', options); cm.setOption('lint', options);
cm.refresh(); // enabling/disabling linting changes the gutter width // enabling/disabling linting changes the gutter width
cm.refresh();
updateLintReport(cm, 200); updateLintReport(cm, 200);
}); });
} }
@ -161,7 +162,8 @@ function renderLintReport(someBlockChanged) {
} }
function resizeLintReport() { function resizeLintReport() {
const magicBuffer = 20; // subtracted value to prevent scrollbar // subtracted value to prevent scrollbar
const magicBuffer = 20;
const content = $('#lint table'); const content = $('#lint table');
if (content) { if (content) {
const bounds = content.getBoundingClientRect(); const bounds = content.getBoundingClientRect();