Bug 1292591 - use reject-some-requires eslint rule in sourceeditor; r=gregtatum

MozReview-Commit-ID: LdPU8bdSGd5

--HG--
extra : rebase_source : a650e325a168b563022c474e0bdb0044f5ee8c1a
This commit is contained in:
Tom Tromey 2016-08-05 09:09:27 -06:00
parent ce87179fdf
commit 0ffbda8268
6 changed files with 66 additions and 46 deletions

View File

@ -97,7 +97,7 @@ devtools/client/shared/redux/middleware/test/**
devtools/client/shared/test/**
!devtools/client/shared/test/test-actor-registry.js
devtools/client/shared/widgets/*.jsm
devtools/client/sourceeditor/**
devtools/client/sourceeditor/test/*.js
devtools/client/webaudioeditor/**
devtools/client/webconsole/**
!devtools/client/webconsole/panel.js

View File

@ -0,0 +1,12 @@
{
// Extend from the devtools eslintrc.
"extends": "../../.eslintrc",
"rules": {
// The inspector is being migrated to HTML and cleaned of
// chrome-privileged code, so this rule disallows requiring chrome
// code. Some files here disable this rule still. The
// goal is to enable the rule globally on all files.
"mozilla/reject-some-requires": [2, "^(chrome|chrome:.*|resource:.*|devtools/server/.*|.*\\.jsm)$"],
},
}

View File

@ -71,17 +71,17 @@ function initializeAutoCompletion(ctx, options = {}) {
let updateArgHintsCallback = cm.tern.updateArgHints.bind(cm.tern, cm);
cm.on("cursorActivity", updateArgHintsCallback);
keyMap[autocompleteKey] = cm => {
cm.tern.getHint(cm, data => {
keyMap[autocompleteKey] = cmArg => {
cmArg.tern.getHint(cmArg, data => {
CodeMirror.on(data, "shown", () => ed.emit("before-suggest"));
CodeMirror.on(data, "close", () => ed.emit("after-suggest"));
CodeMirror.on(data, "select", () => ed.emit("suggestion-entered"));
CodeMirror.showHint(cm, (cm, cb) => cb(data), { async: true });
CodeMirror.showHint(cmArg, (cmIgnore, cb) => cb(data), { async: true });
});
};
keyMap[Editor.keyFor("showInformation2", { noaccel: true })] = cm => {
cm.tern.showType(cm, null, () => {
keyMap[Editor.keyFor("showInformation2", { noaccel: true })] = cmArg => {
cmArg.tern.showType(cmArg, null, () => {
ed.emit("show-information");
});
};

View File

@ -4,7 +4,11 @@
"use strict";
/* eslint-disable complexity */
/* eslint-disable mozilla/reject-some-requires */
const { Cc, Ci } = require("chrome");
/* eslint-enable mozilla/reject-some-requires */
const {cssTokenizer, cssTokenizerWithLineColumn} = require("devtools/shared/css-parsing-utils");
/**
@ -52,6 +56,7 @@ const {cssTokenizer, cssTokenizerWithLineColumn} = require("devtools/shared/css-
// Autocompletion types.
/* eslint-disable no-inline-comments */
const CSS_STATES = {
"null": "null",
property: "property", // foo { bar|: … }
@ -71,6 +76,7 @@ const SELECTOR_STATES = {
attribute: "attribute", // foo[b|
value: "value", // foo[bar=b|
};
/* eslint-enable no-inline-comments */
const { properties, propertyNames } = getCSSKeywords();
@ -979,11 +985,11 @@ CSSCompleter.prototype = {
*/
getInfoAt: function (source, caret) {
// Limits the input source till the {line, ch} caret position
function limit(source, {line, ch}) {
function limit(sourceArg, {line, ch}) {
line++;
let list = source.split("\n");
let list = sourceArg.split("\n");
if (list.length < line) {
return source;
return sourceArg;
}
if (line == 1) {
return list[0].slice(0, ch);
@ -1036,11 +1042,11 @@ CSSCompleter.prototype = {
continue;
}
let state = this.resolveState(limitedSource, {
let forwState = this.resolveState(limitedSource, {
line: line,
ch: token.endOffset + ech
});
if (check(state)) {
if (check(forwState)) {
if (prevToken && prevToken.tokenType == "whitespace") {
token = prevToken;
}
@ -1097,11 +1103,11 @@ CSSCompleter.prototype = {
continue;
}
let state = this.resolveState(limitedSource, {
let backState = this.resolveState(limitedSource, {
line: line,
ch: token.startOffset
});
if (check(state)) {
if (check(backState)) {
if (tokens[i + 1] && tokens[i + 1].tokenType == "whitespace") {
token = tokens[i + 1];
}
@ -1126,16 +1132,16 @@ CSSCompleter.prototype = {
// either when the state changes or the selector becomes empty and a
// single selector can span multiple lines.
// Backward loop to determine the beginning location of the selector.
let start = traverseBackwards(state => {
return (state != CSS_STATES.selector ||
let start = traverseBackwards(backState => {
return (backState != CSS_STATES.selector ||
(this.selector == "" && this.selectorBeforeNot == null));
});
line = caret.line;
limitedSource = limit(source, caret);
// Forward loop to determine the ending location of the selector.
let end = traverseForward(state => {
return (state != CSS_STATES.selector ||
let end = traverseForward(forwState => {
return (forwState != CSS_STATES.selector ||
(this.selector == "" && this.selectorBeforeNot == null));
});
@ -1180,11 +1186,11 @@ CSSCompleter.prototype = {
} else if (state == CSS_STATES.value) {
// CSS value can be multiline too, so we go forward and backwards to
// determine the bounds of the value at caret
let start = traverseBackwards(state => state != CSS_STATES.value, true);
let start = traverseBackwards(backState => backState != CSS_STATES.value, true);
line = caret.line;
limitedSource = limit(source, caret);
let end = traverseForward(state => state != CSS_STATES.value);
let end = traverseForward(forwState => forwState != CSS_STATES.value);
let value = source.split("\n").slice(start.line, end.line + 1);
value[value.length - 1] = value[value.length - 1].substring(0, end.ch);

View File

@ -130,7 +130,7 @@ function hasBreakpoint(ctx, line) {
* emit a breakpointAdded event.
*/
function addBreakpoint(ctx, line, cond) {
function _addBreakpoint(ctx, line, cond) {
function _addBreakpoint() {
let { ed, cm } = ctx;
let meta = dbginfo.get(ed);
let info = cm.lineInfo(line);
@ -166,9 +166,9 @@ function addBreakpoint(ctx, line, cond) {
// If lineInfo() returns null, wait a tick to give the editor a chance to
// initialize properly.
if (ctx.cm.lineInfo(line) === null) {
DevToolsUtils.executeSoon(() => _addBreakpoint(ctx, line, cond));
DevToolsUtils.executeSoon(() => _addBreakpoint());
} else {
_addBreakpoint(ctx, line, cond);
_addBreakpoint();
}
return deferred.promise;
}
@ -221,10 +221,7 @@ function removeBreakpoint(ctx, line) {
}
function moveBreakpoint(ctx, fromLine, toLine) {
let { ed, cm } = ctx;
let fromTop = cm.cursorCoords({ line: fromLine }).top;
let toTop = cm.cursorCoords({ line: toLine }).top;
let { ed } = ctx;
ed.removeBreakpoint(fromLine);
ed.addBreakpoint(toLine);
@ -245,7 +242,7 @@ function setBreakpointCondition(ctx, line) {
}
function removeBreakpointCondition(ctx, line) {
let { ed, cm } = ctx;
let { ed } = ctx;
ed.removeLineClass(line, "conditional");
}
@ -334,4 +331,6 @@ function findPrev(ctx, query) {
setBreakpointCondition, removeBreakpointCondition, getBreakpoints, removeBreakpoints,
setDebugLocation, getDebugLocation, clearDebugLocation, find, findNext,
findPrev
].forEach(func => module.exports[func.name] = func);
].forEach(func => {
module.exports[func.name] = func;
});

View File

@ -6,7 +6,9 @@
"use strict";
const { Cu, Cc, Ci } = require("chrome");
/* eslint-disable mozilla/reject-some-requires */
const {Cc, Ci} = require("chrome");
/* eslint-enable mozilla/reject-some-requires */
const {
EXPAND_TAB,
@ -85,7 +87,8 @@ const CM_IFRAME =
" <style>" +
" html, body { height: 100%; }" +
" body { margin: 0; overflow: hidden; }" +
" .CodeMirror { width: 100%; height: 100% !important; line-height: 1.25 !important;}" +
" .CodeMirror { width: 100%; height: 100% !important; " +
"line-height: 1.25 !important;}" +
" </style>" +
CM_STYLES.map(style => "<link rel='stylesheet' href='" + style + "'>").join("\n") +
" </head>" +
@ -417,13 +420,13 @@ Editor.prototype = {
});
cm.on("cursorActivity", () => this.emit("cursorActivity"));
cm.on("gutterClick", (cm, line, gutter, ev) => {
cm.on("gutterClick", (cmArg, line, gutter, ev) => {
let head = { line: line, ch: 0 };
let tail = { line: line, ch: this.getText(line).length };
// Shift-click on a gutter selects the whole line.
if (ev.shiftKey) {
cm.setSelection(head, tail);
cmArg.setSelection(head, tail);
return;
}
@ -822,7 +825,7 @@ Editor.prototype = {
* You don't need to worry about removing these event listeners.
* They're automatically orphaned when clearing markers.
*/
setMarkerListeners: function (line, gutterName, markerClass, events, data) {
setMarkerListeners: function (line, gutterName, markerClass, eventsArg, data) {
if (!this.hasMarker(line, gutterName, markerClass)) {
return;
}
@ -830,8 +833,8 @@ Editor.prototype = {
let cm = editors.get(this);
let marker = cm.lineInfo(line).gutterMarkers[gutterName];
for (let name in events) {
let listener = events[name].bind(this, line, marker, data);
for (let name in eventsArg) {
let listener = eventsArg[name].bind(this, line, marker, data);
marker.addEventListener(name, listener);
}
},
@ -1001,8 +1004,8 @@ Editor.prototype = {
// Handle LINE:COLUMN as well as LINE
let match = line.toString().match(RE_JUMP_TO_LINE);
if (match) {
let [, line, column ] = match;
this.setCursor({line: line - 1, ch: column ? column - 1 : 0 });
let [, matchLine, column ] = match;
this.setCursor({line: matchLine - 1, ch: column ? column - 1 : 0 });
}
});
},
@ -1292,24 +1295,24 @@ function getCSSKeywords() {
let domUtils = Cc["@mozilla.org/inspector/dom-utils;1"]
.getService(Ci.inIDOMUtils);
let cssProperties = domUtils.getCSSPropertyNames(domUtils.INCLUDE_ALIASES);
let cssColors = {};
let cssValues = {};
cssProperties.forEach(property => {
let properties = domUtils.getCSSPropertyNames(domUtils.INCLUDE_ALIASES);
let colors = {};
let values = {};
properties.forEach(property => {
if (property.includes("color")) {
domUtils.getCSSValuesForProperty(property).forEach(value => {
cssColors[value] = true;
colors[value] = true;
});
} else {
domUtils.getCSSValuesForProperty(property).forEach(value => {
cssValues[value] = true;
values[value] = true;
});
}
});
return {
cssProperties: keySet(cssProperties),
cssValues: cssValues,
cssColors: cssColors
cssProperties: keySet(properties),
cssValues: values,
cssColors: colors
};
}