Fix no-inline-comments issues

This commit is contained in:
Rob Garrison 2017-08-20 15:14:12 -05:00
parent a3b8b7d168
commit d563495c26
10 changed files with 125 additions and 66 deletions

View File

@ -10,14 +10,21 @@ var SLOPPY_REGEXP_PREFIX = '\0';
// Note, only 'var'-declared variables are visible from another extension page
// eslint-disable-next-line no-var
var cachedStyles = {
list: null, // array of all styles
byId: new Map(), // all styles indexed by id
filters: new Map(), // filterStyles() parameters mapped to the returned results, 10k max
regexps: new Map(), // compiled style regexps
urlDomains: new Map(), // getDomain() results for 100 last checked urls
// array of all styles
list: null,
// all styles indexed by id
byId: new Map(),
// filterStyles() parameters mapped to the returned results, 10k max
filters: new Map(),
// compiled style regexps
regexps: new Map(),
// getDomain() results for 100 last checked urls
urlDomains: new Map(),
mutex: {
inProgress: false, // while getStyles() is reading IndexedDB all subsequent calls
onDone: [], // to getStyles() are queued and resolved when the first one finishes
// while getStyles() is reading IndexedDB all subsequent calls
inProgress: false,
// to getStyles() are queued and resolved when the first one finishes
onDone: [],
},
};
@ -248,8 +255,10 @@ function saveStyle(style) {
});
}
if (reason === 'import') {
style.originalDigest = style.originalDigest || style.styleDigest; // TODO: remove in the future
delete style.styleDigest; // TODO: remove in the future
// TODO: remove in the future
style.originalDigest = style.originalDigest || style.styleDigest;
// TODO: remove in the future
delete style.styleDigest;
if (typeof style.originalDigest !== 'string' || style.originalDigest.length !== 40) {
delete style.originalDigest;
}
@ -524,7 +533,8 @@ function cleanupCachedFilters({force = false} = {}) {
const now = Date.now();
const timeSpan = now - oldestHit;
const recencyWeight = 5 / size;
const hitWeight = 1 / 4; // we make ~4 hits per URL
// we make ~4 hits per URL
const hitWeight = 1 / 4;
const lastHitWeight = 10;
// delete the oldest 10%
[...cachedStyles.filters.entries()]

View File

@ -100,7 +100,8 @@ var updater = {
}
return !save ? json :
saveStyle(Object.assign(json, {
name: null, // keep local name customizations
// keep local name customizations
name: null,
reason: 'update',
}));
}

View File

@ -276,7 +276,8 @@ function initDocRewriteObserver() {
}
ROOT = document.documentElement;
for (const el of styleElements.values()) {
el.textContent += ' '; // invalidate CSSOM cache
// invalidate CSSOM cache
el.textContent += ' ';
addStyleElement(document.importNode(el, true));
}
};
@ -350,7 +351,8 @@ function orphanCheck() {
window.removeEventListener(chrome.runtime.id, orphanCheck, true);
// we can't detach chrome.runtime.onMessage because it's no longer connected internally
// we can destroy our globals in this context to free up memory
[ // functions
[
// functions
'addStyleElement',
'applyOnMessage',
'applySections',

View File

@ -1,6 +1,7 @@
'use strict';
const CHROMIUM = /Chromium/.test(navigator.userAgent); // non-Windows Chromium
// non-Windows Chromium
const CHROMIUM = /Chromium/.test(navigator.userAgent);
const FIREFOX = /Firefox/.test(navigator.userAgent);
const VIVALDI = /Vivaldi/.test(navigator.userAgent);
const OPERA = /OPR/.test(navigator.userAgent);

View File

@ -1,3 +1,5 @@
'use strict';
window.stylelintDefaultConfig = (defaultSeverity => ({
// 'sugarss' is a indent-based syntax like Sass or Stylus
// ref: https://github.com/postcss/postcss#syntaxes
@ -20,7 +22,8 @@ window.stylelintDefaultConfig = (defaultSeverity => ({
'function-linear-gradient-no-nonstandard-direction': [true, defaultSeverity],
'keyframe-declaration-no-important': [true, defaultSeverity],
'media-feature-name-no-unknown': [true, defaultSeverity],
'no-empty-source': false, /* recommended true */
/* recommended true */
'no-empty-source': false,
'no-extra-semicolons': [true, defaultSeverity],
'no-invalid-double-slash-comments': [true, defaultSeverity],
'property-no-unknown': [true, defaultSeverity],

View File

@ -4,34 +4,56 @@
// eslint-disable-next-line no-var
var prefs = new function Prefs() {
const defaults = {
'openEditInWindow': false, // new editor opens in a own browser window
'windowPosition': {}, // detached window position
'show-badge': true, // display text on popup menu icon
'disableAll': false, // boss key
'exposeIframes': false, // Add 'stylus-iframe' attribute to HTML element in all iframes
// new editor opens in a own browser window
'openEditInWindow': false,
// detached window position
'windowPosition': {},
// display text on popup menu icon
'show-badge': true,
// boss key
'disableAll': false,
// Add 'stylus-iframe' attribute to HTML element in all iframes
'exposeIframes': false,
'popup.breadcrumbs': true, // display 'New style' links as URL breadcrumbs
'popup.breadcrumbs.usePath': false, // use URL path for 'this URL'
'popup.enabledFirst': true, // display enabled styles before disabled styles
'popup.stylesFirst': true, // display enabled styles before disabled styles
// display 'New style' links as URL breadcrumbs
'popup.breadcrumbs': true,
// use URL path for 'this URL'
'popup.breadcrumbs.usePath': false,
// display enabled styles before disabled styles
'popup.enabledFirst': true,
// display enabled styles before disabled styles
'popup.stylesFirst': true,
'manage.onlyEnabled': false, // display only enabled styles
'manage.onlyLocal': false, // display only styles created locally
// display only enabled styles
'manage.onlyEnabled': false,
// display only styles created locally
'manage.onlyLocal': false,
'manage.onlyEnabled.invert': false, // display only disabled styles
'manage.onlyLocal.invert': false, // display only externally installed styles
'manage.newUI': true, // use the new compact layout
'manage.newUI.favicons': false, // show favicons for the sites in applies-to
'manage.newUI.faviconsGray': true, // gray out favicons
'manage.newUI.targets': 3, // max number of applies-to targets visible: 0 = none
// use the new compact layout
'manage.newUI': true,
// show favicons for the sites in applies-to
'manage.newUI.favicons': false,
// gray out favicons
'manage.newUI.faviconsGray': true,
// max number of applies-to targets visible: 0 = none
'manage.newUI.targets': 3,
'editor.options': {}, // CodeMirror.defaults.*
'editor.lineWrapping': true, // word wrap
'editor.smartIndent': true, // 'smart' indent
'editor.indentWithTabs': false, // smart indent with tabs
'editor.tabSize': 4, // tab width, in spaces
// CodeMirror.defaults.*
'editor.options': {},
// word wrap
'editor.lineWrapping': true,
// 'smart' indent
'editor.smartIndent': true,
// smart indent with tabs
'editor.indentWithTabs': false,
// tab width, in spaces
'editor.tabSize': 4,
'editor.keyMap': navigator.appVersion.indexOf('Windows') > 0 ? 'sublime' : 'default',
'editor.theme': 'default', // CSS theme
'editor.beautify': { // CSS beautifier
// CSS theme
'editor.theme': 'default',
// CSS beautifier
'editor.beautify': {
selector_separator_newline: true,
newline_before_open_brace: false,
newline_after_open_brace: true,
@ -41,24 +63,34 @@ var prefs = new function Prefs() {
end_with_newline: false,
indent_conditional: true,
},
'editor.lintDelay': 500, // lint gutter marker update delay, ms
'editor.linter': 'csslint', // Choose csslint or stylelint
'editor.lintReportDelay': 4500, // lint report update delay, ms
'editor.matchHighlight': 'token', // token = token/word under cursor even if nothing is selected
// lint gutter marker update delay, ms
'editor.lintDelay': 500,
// Options: 'csslint', 'stylelint' or 'null'
'editor.linter': 'csslint',
// lint report update delay, ms
'editor.lintReportDelay': 4500,
// token = token/word under cursor even if nothing is selected
// selection = only when something is selected
// '' (empty string) = disabled
'editor.autocompleteOnTyping': false, // show autocomplete dropdown on typing a word token
'editor.contextDelete': contextDeleteMissing(), // "Delete" item in context menu
'editor.matchHighlight': 'token',
// show autocomplete dropdown on typing a word token
'editor.autocompleteOnTyping': false,
// "Delete" item in context menu
'editor.contextDelete': contextDeleteMissing(),
'iconset': 0, // 0 = dark-themed icon
// 1 = light-themed icon
// 0 = dark-themed icon; 1 = light-themed icon
'iconset': 0,
'badgeDisabled': '#8B0000', // badge background color when disabled
'badgeNormal': '#006666', // badge background color
// badge background color when disabled
'badgeDisabled': '#8B0000',
// badge background color
'badgeNormal': '#006666',
'popupWidth': 246, // popup width in pixels
// popup width in pixels
'popupWidth': 246,
'updateInterval': 24, // user-style automatic update interval, hours (0 = disable)
// user-style automatic update interval, hours (0 = disable)
'updateInterval': 24,
};
const values = deepCopy(defaults);

View File

@ -72,8 +72,10 @@ function importFromString(jsonString) {
let index = 0;
let lastRenderTime = performance.now();
const renderQueue = [];
const RENDER_NAP_TIME_MAX = 1000; // ms
const RENDER_QUEUE_MAX = 50; // number of styles
// ms
const RENDER_NAP_TIME_MAX = 1000;
// number of styles
const RENDER_QUEUE_MAX = 50;
const SAVE_OPTIONS = {reason: 'import', notify: false};
return new Promise(proceed);

View File

@ -1,13 +1,20 @@
'use strict';
function messageBox({
title, // [mandatory] string
contents, // [mandatory] 1) DOM element 2) string
className = '', // string, CSS class name of the message box element
buttons = [], // array of strings used as labels
onshow, // function(messageboxElement) invoked after the messagebox is shown
blockScroll, // boolean, blocks the page scroll
}) { // RETURNS: Promise resolved to {button[number], enter[boolean], esc[boolean]}
// [mandatory] string
title,
// [mandatory] 1) DOM element 2) string
contents,
// string, CSS class name of the message box element
className = '',
// array of strings used as labels
buttons = [],
// function(messageboxElement) invoked after the messagebox is shown
onshow,
// boolean, blocks the page scroll
blockScroll,
// RETURNS: Promise resolved to {button[number], enter[boolean], esc[boolean]}
}) {
initOwnListeners();
bindGlobalListeners();
createElement();

View File

@ -143,7 +143,8 @@ function initPopup(url) {
title: `url-prefix("${url}")`,
textContent: prefs.get('popup.breadcrumbs.usePath')
? new URL(url).pathname.slice(1)
: t('writeStyleForURL').replace(/ /g, '\u00a0'), // this URL
// this URL
: t('writeStyleForURL').replace(/ /g, '\u00a0'),
onclick: handleEvent.openLink,
});
if (prefs.get('popup.breadcrumbs')) {

View File

@ -22,7 +22,7 @@
CodeMirror.registerHelper('lint', 'csslint', text => {
const found = [];
if (window.CSSLint) {
/* STYLISH: hack start (part 1) */
/* STYLUS: hack start (part 1) */
const rules = CSSLint.getRules();
const allowedRules = [
'display-property-grouping',
@ -37,7 +37,7 @@
CSSLint.addRule(rule);
}
});
/* STYLISH: hack end */
/* STYLUS: hack end */
const results = CSSLint.verify(text);
const messages = results.messages;
@ -46,7 +46,7 @@
for (let i = 0; i < messages.length; i++) {
message = messages[i];
/* STYLISH: hack start (part 2) */
/* STYLUS: hack start (part 2) */
if (message.type === 'warning') {
// @font-face {font-family: 'Ampersand'; unicode-range: U+26;}
if (message.message.indexOf('unicode-range') !== -1) {
@ -59,7 +59,7 @@
continue;
}
}
/* STYLISH: hack end */
/* STYLUS: hack end */
const startLine = message.line - 1;
const endLine = message.line - 1;
const startCol = message.col - 1;