misc: configure and fix eslint linting (#66719)
This commit is contained in:
parent
c84c5afa46
commit
7ee0085317
|
@ -5,3 +5,76 @@ extends: eslint:recommended
|
|||
parserOptions:
|
||||
ecmaVersion: 13
|
||||
sourceType: module
|
||||
rules:
|
||||
# https://standardjs.com/rules.html
|
||||
|
||||
# Linting
|
||||
array-callback-return: error
|
||||
constructor-super: error
|
||||
eqeqeq: [error, always, {null: ignore}]
|
||||
handle-callback-err: error
|
||||
no-array-constructor: error
|
||||
no-caller: error
|
||||
no-class-assign: error
|
||||
no-cond-assign: error
|
||||
no-const-assign: error
|
||||
no-control-regex: error
|
||||
no-debugger: error
|
||||
no-delete-var: error
|
||||
no-dupe-args: error
|
||||
no-dupe-class-members: error
|
||||
no-dupe-keys: error
|
||||
no-duplicate-case: error
|
||||
no-duplicate-imports: error
|
||||
no-empty-character-class: error
|
||||
no-empty-pattern: error
|
||||
no-eval: error
|
||||
no-ex-assign: error
|
||||
no-extend-native: error
|
||||
no-extra-boolean-cast: error
|
||||
no-fallthrough: error
|
||||
no-func-assign: error
|
||||
no-global-assign: error
|
||||
no-implied-eval: error
|
||||
no-inner-declarations: error
|
||||
no-invalid-regexp: error
|
||||
no-iterator: error
|
||||
no-labels: error
|
||||
no-new-func: error
|
||||
no-new-object: error
|
||||
no-new-require: error
|
||||
no-new-symbol: error
|
||||
no-new-wrappers: error
|
||||
no-new: error
|
||||
no-obj-calls: error
|
||||
no-octal-escape: error
|
||||
no-octal: error
|
||||
no-proto: error
|
||||
no-redeclare: error
|
||||
no-regex-spaces: error
|
||||
no-return-assign: error
|
||||
no-self-assign: error
|
||||
no-self-compare: error
|
||||
no-sequences: error
|
||||
no-shadow-restricted-names: error
|
||||
no-sparse-arrays: error
|
||||
no-template-curly-in-string: error
|
||||
no-this-before-super: error
|
||||
no-throw-literal: error
|
||||
no-undef: error
|
||||
no-unexpected-multiline: error
|
||||
no-unmodified-loop-condition: error
|
||||
no-unneeded-ternary: error
|
||||
no-unreachable: error
|
||||
no-unsafe-finally: error
|
||||
no-unsafe-negation: error
|
||||
no-unused-vars: error
|
||||
no-use-before-define: [error, {functions: false, variables: false, classes: false}]
|
||||
no-useless-call: error
|
||||
no-useless-computed-key: error
|
||||
no-useless-constructor: error
|
||||
no-useless-escape: error
|
||||
no-var: error
|
||||
no-with: error
|
||||
use-isnan: error
|
||||
valid-typeof: error
|
||||
|
|
|
@ -16,9 +16,9 @@ export function wrapInList(listType, attrs) {
|
|||
let range = $from.blockRange($to), doJoin = false, outerRange = range
|
||||
if (!range) return false
|
||||
// This is at the top of an existing list item
|
||||
if (range.depth >= 2 && $from.node(range.depth - 1).type.compatibleContent(listType) && range.startIndex == 0) {
|
||||
if (range.depth >= 2 && $from.node(range.depth - 1).type.compatibleContent(listType) && range.startIndex === 0) {
|
||||
// Don't do anything if this is the top of the list
|
||||
if ($from.index(range.depth - 1) == 0) return false
|
||||
if ($from.index(range.depth - 1) === 0) return false
|
||||
let $insert = state.doc.resolve(range.start - 2)
|
||||
outerRange = new NodeRange($insert, $insert, range.depth)
|
||||
if (range.endIndex < range.parent.childCount)
|
||||
|
@ -41,7 +41,7 @@ function doWrapInList(tr, range, wrappers, joinBefore, listType) {
|
|||
new Slice(content, 0, 0), wrappers.length, true))
|
||||
|
||||
let found = 0
|
||||
for (let i = 0; i < wrappers.length; i++) if (wrappers[i].type == listType) found = i + 1
|
||||
for (let i = 0; i < wrappers.length; i++) if (wrappers[i].type === listType) found = i + 1
|
||||
let splitDepth = wrappers.length - found
|
||||
|
||||
let splitPos = range.start + wrappers.length - (joinBefore ? 2 : 0), parent = range.parent
|
||||
|
@ -63,13 +63,13 @@ export function splitListItem(itemType) {
|
|||
let {$from, $to, node} = state.selection
|
||||
if ((node && node.isBlock) || $from.depth < 2 || !$from.sameParent($to)) return false
|
||||
let grandParent = $from.node(-1)
|
||||
if (grandParent.type != itemType) return false
|
||||
if ($from.parent.content.size == 0 && $from.node(-1).childCount == $from.indexAfter(-1)) {
|
||||
if (grandParent.type !== itemType) return false
|
||||
if ($from.parent.content.size === 0 && $from.node(-1).childCount === $from.indexAfter(-1)) {
|
||||
// In an empty block. If this is a nested list, the wrapping
|
||||
// list item should be split. Otherwise, bail out and let next
|
||||
// command handle lifting.
|
||||
if ($from.depth == 2 || $from.node(-3).type != itemType ||
|
||||
$from.index(-2) != $from.node(-2).childCount - 1) return false
|
||||
if ($from.depth === 2 || $from.node(-3).type !== itemType ||
|
||||
$from.index(-2) !== $from.node(-2).childCount - 1) return false
|
||||
if (dispatch) {
|
||||
let wrap = Fragment.empty
|
||||
let depthBefore = $from.index(-1) ? 1 : $from.index(-2) ? 2 : 3
|
||||
|
@ -86,14 +86,14 @@ export function splitListItem(itemType) {
|
|||
let sel = -1
|
||||
tr.doc.nodesBetween(start, tr.doc.content.size, (node, pos) => {
|
||||
if (sel > -1) return false
|
||||
if (node.isTextblock && node.content.size == 0) sel = pos + 1
|
||||
if (node.isTextblock && node.content.size === 0) sel = pos + 1
|
||||
})
|
||||
if (sel > -1) tr.setSelection(state.selection.constructor.near(tr.doc.resolve(sel)))
|
||||
dispatch(tr.scrollIntoView())
|
||||
}
|
||||
return true
|
||||
}
|
||||
let nextType = $to.pos == $from.end() ? grandParent.contentMatchAt(0).defaultType : null
|
||||
let nextType = $to.pos === $from.end() ? grandParent.contentMatchAt(0).defaultType : null
|
||||
let tr = state.tr.delete($from.pos, $to.pos)
|
||||
let types = nextType && [null, {type: nextType}]
|
||||
if (!canSplit(tr.doc, $from.pos, 2, types)) return false
|
||||
|
@ -108,10 +108,10 @@ export function splitListItem(itemType) {
|
|||
export function liftListItem(itemType) {
|
||||
return function(state, dispatch) {
|
||||
let {$from, $to} = state.selection
|
||||
let range = $from.blockRange($to, node => node.childCount && node.firstChild.type == itemType)
|
||||
let range = $from.blockRange($to, node => node.childCount && node.firstChild.type === itemType)
|
||||
if (!range) return false
|
||||
if (!dispatch) return true
|
||||
if ($from.node(range.depth - 1).type == itemType) // Inside a parent list
|
||||
if ($from.node(range.depth - 1).type === itemType) // Inside a parent list
|
||||
return liftToOuterList(state, dispatch, itemType, range)
|
||||
else // Outer list node
|
||||
return liftOutOfList(state, dispatch, range)
|
||||
|
@ -139,8 +139,8 @@ function liftOutOfList(state, dispatch, range) {
|
|||
tr.delete(pos - 1, pos + 1)
|
||||
}
|
||||
let $start = tr.doc.resolve(range.start), item = $start.nodeAfter
|
||||
if (tr.mapping.map(range.end) != range.start + $start.nodeAfter.nodeSize) return false
|
||||
let atStart = range.startIndex == 0, atEnd = range.endIndex == list.childCount
|
||||
if (tr.mapping.map(range.end) !== range.start + $start.nodeAfter.nodeSize) return false
|
||||
let atStart = range.startIndex === 0, atEnd = range.endIndex === list.childCount
|
||||
let parent = $start.node(-1), indexBefore = $start.index(-1)
|
||||
if (!parent.canReplace(indexBefore + (atStart ? 0 : 1), indexBefore + 1,
|
||||
item.content.append(atEnd ? Fragment.empty : Fragment.from(list))))
|
||||
|
@ -163,15 +163,15 @@ function liftOutOfList(state, dispatch, range) {
|
|||
export function sinkListItem(itemType) {
|
||||
return function(state, dispatch) {
|
||||
let {$from, $to} = state.selection
|
||||
let range = $from.blockRange($to, node => node.childCount && node.firstChild.type == itemType)
|
||||
let range = $from.blockRange($to, node => node.childCount && node.firstChild.type === itemType)
|
||||
if (!range) return false
|
||||
let startIndex = range.startIndex
|
||||
if (startIndex == 0) return false
|
||||
if (startIndex === 0) return false
|
||||
let parent = range.parent, nodeBefore = parent.child(startIndex - 1)
|
||||
if (nodeBefore.type != itemType) return false
|
||||
if (nodeBefore.type !== itemType) return false
|
||||
|
||||
if (dispatch) {
|
||||
let nestedBefore = nodeBefore.lastChild && nodeBefore.lastChild.type == parent.type
|
||||
let nestedBefore = nodeBefore.lastChild && nodeBefore.lastChild.type === parent.type
|
||||
let inner = Fragment.from(nestedBefore ? itemType.create() : null)
|
||||
let slice = new Slice(Fragment.from(itemType.create(null, Fragment.from(parent.type.create(null, inner)))),
|
||||
nestedBefore ? 3 : 1, 0)
|
||||
|
|
|
@ -3,7 +3,7 @@ import {wrapIn, setBlockType, chainCommands, toggleMark, exitCode,
|
|||
import {splitListItem, liftListItem} from "./godo-additional-commands.mjs"
|
||||
import {undo, redo} from "prosemirror-history"
|
||||
|
||||
const mac = typeof navigator != "undefined" ? /Mac/.test(navigator.platform) : false
|
||||
const mac = typeof navigator !== "undefined" ? /Mac/.test(navigator.platform) : false
|
||||
|
||||
// :: (Schema, ?Object) → Object
|
||||
// Inspect the given schema looking for marks and nodes from the
|
||||
|
@ -51,26 +51,26 @@ export function buildKeymap(schema, mapKeys, options) {
|
|||
bind("Mod-BracketLeft", lift)
|
||||
bind("Escape", selectParentNode)
|
||||
|
||||
if (type = schema.marks.strong) {
|
||||
if ((type = schema.marks.strong)) {
|
||||
bind("Mod-b", toggleMark(type))
|
||||
bind("Mod-B", toggleMark(type))
|
||||
}
|
||||
if (type = schema.marks.em) {
|
||||
if ((type = schema.marks.em)) {
|
||||
bind("Mod-i", toggleMark(type))
|
||||
bind("Mod-I", toggleMark(type))
|
||||
}
|
||||
if (type = schema.marks.code)
|
||||
if ((type = schema.marks.code))
|
||||
bind("Mod-`", toggleMark(type))
|
||||
|
||||
if (type = schema.nodes.blockquote)
|
||||
if ((type = schema.nodes.blockquote))
|
||||
bind("Ctrl->", wrapIn(type))
|
||||
|
||||
if (type = schema.nodes.list_item) {
|
||||
if ((type = schema.nodes.list_item)) {
|
||||
bind("Enter", splitListItem(type))
|
||||
bind("Mod-[", liftListItem(type))
|
||||
}
|
||||
|
||||
if (type = schema.nodes.hard_break) {
|
||||
if ((type = schema.nodes.hard_break)) {
|
||||
let br = type, cmd = chainCommands(exitCode, (state, dispatch) => {
|
||||
dispatch(state.tr.replaceSelectionWith(br.create()).scrollIntoView())
|
||||
return true
|
||||
|
@ -80,19 +80,19 @@ export function buildKeymap(schema, mapKeys, options) {
|
|||
if (mac) bind("Ctrl-Enter", cmd)
|
||||
}
|
||||
|
||||
if (type = schema.nodes.paragraph)
|
||||
if ((type = schema.nodes.paragraph))
|
||||
bind("Shift-Ctrl-0", setBlockType(type))
|
||||
|
||||
if (type = schema.nodes.code_block)
|
||||
if ((type = schema.nodes.code_block))
|
||||
bind("Shift-Ctrl-\\", setBlockType(type))
|
||||
|
||||
if (type = schema.nodes.heading) {
|
||||
if ((type = schema.nodes.heading)) {
|
||||
options.heading_levels.forEach( (level, index) => {
|
||||
bind(`Shift-Ctrl-${index+1}`, setBlockType(type, {level: level}))
|
||||
});
|
||||
}
|
||||
|
||||
if (type = schema.nodes.horizontal_rule) {
|
||||
if ((type = schema.nodes.horizontal_rule)) {
|
||||
let hr = type
|
||||
bind("Mod-_", (state, dispatch) => {
|
||||
dispatch(state.tr.replaceSelectionWith(hr.create()).scrollIntoView())
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
const dLanguage = document.documentElement.lang.split('-')[0];
|
||||
const nLanguage = navigator.languages ? navigator.languages[0] : navigator.language || navigator.userLanguage;
|
||||
const language = (dLanguage) ? dLanguage : nLanguage;
|
||||
const godoLanguage = (language == "fr") ? language : "en";
|
||||
const godoLanguage = (language === "fr") ? language : "en";
|
||||
|
||||
const languageContent = {
|
||||
"a": {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import {toggleMark, setBlockType, wrapIn, chainCommands} from "prosemirror-commands";
|
||||
import {toggleMark, setBlockType, chainCommands} from "prosemirror-commands";
|
||||
import {wrapInList, liftListItem} from "./godo-additional-commands.mjs";
|
||||
import getLanguage from "./godo-menus-language.mjs";
|
||||
|
||||
|
@ -52,7 +52,7 @@ class Menu {
|
|||
} else {
|
||||
menuItem.classList.remove('active');
|
||||
}
|
||||
menuItem.disabled = (is_disabled) ? true : false;
|
||||
menuItem.disabled = is_disabled;
|
||||
}
|
||||
|
||||
update_blocks(view, state) {
|
||||
|
@ -63,14 +63,13 @@ class Menu {
|
|||
return to <= $from.end() && $from.parent.hasMarkup(type, options)
|
||||
};
|
||||
const is_active = (active) ? active(state) : active_default();
|
||||
const is_disabled = !run(state, null, view);;
|
||||
const is_disabled = !run(state, null, view);
|
||||
this.set_menu_item(dom, is_active, is_disabled);
|
||||
}
|
||||
}
|
||||
|
||||
update_marks( view, state ) {
|
||||
let $sel = state.selection;
|
||||
const empty = $sel.empty;
|
||||
const $cursor = $sel.$cursor;
|
||||
const ranges = $sel.ranges;
|
||||
let get_is_active;
|
||||
|
@ -78,7 +77,7 @@ class Menu {
|
|||
// if single cursor
|
||||
if ($cursor && $cursor.marks()) {
|
||||
const activeMarks = $cursor.marks().map( m => m.type.name);
|
||||
get_is_active = (type) => activeMarks.includes(type.name) ? true : false;
|
||||
get_is_active = (type) => activeMarks.includes(type.name);
|
||||
this.el.classList.add("fade");
|
||||
|
||||
// else = select range
|
||||
|
@ -105,7 +104,7 @@ class Menu {
|
|||
this.el.style.transform = `translate(${left}px, ${end.bottom}px)`;
|
||||
|
||||
// if (view.hasFocus()) this.el.hidden = false;
|
||||
this.el.hidden = (view.hasFocus()) ? false : true;
|
||||
this.el.hidden = view.hasFocus();
|
||||
}
|
||||
|
||||
destroy() { this.el.remove(); }
|
||||
|
@ -115,13 +114,13 @@ class Menu {
|
|||
function linkItem( type ) {
|
||||
return {
|
||||
dom: icon("a"),
|
||||
run( state, dispatch, view ) {
|
||||
run( state, dispatch ) {
|
||||
let chref = prompt("href");
|
||||
toggleMark(type, {href: chref})(state, dispatch);
|
||||
},
|
||||
type
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function setHeader(type, level, icon_id) {
|
||||
return {
|
||||
|
@ -150,17 +149,17 @@ function blocks( schema, h_levels ) {
|
|||
};
|
||||
let type, i = {};
|
||||
|
||||
if (type = schema.nodes.heading) {
|
||||
if ((type = schema.nodes.heading)) {
|
||||
let icon_id = 'h';
|
||||
h_levels.forEach( (level) => {
|
||||
i["setHeader"+level] = setHeader(type, level, icon_id);
|
||||
icon_id = icon_id + "h";
|
||||
});
|
||||
}
|
||||
if (type = schema.nodes.paragraph) {
|
||||
if ((type = schema.nodes.paragraph)) {
|
||||
i.setP = {run: setBlockType(type), dom: icon("p"), type};
|
||||
}
|
||||
if (type = schema.nodes.bullet_list) {
|
||||
if ((type = schema.nodes.bullet_list)) {
|
||||
i.setList = {
|
||||
run: chainCommands(wrapInList(type), liftListItem(schema.nodes.list_item)),
|
||||
dom: icon("ul"),
|
||||
|
@ -188,11 +187,11 @@ function marks( schema ) {
|
|||
};
|
||||
let type, i = {};
|
||||
|
||||
if (type = schema.marks.strong)
|
||||
if ((type = schema.marks.strong))
|
||||
i.toggleStrong = {run: toggleMark(type), dom: icon("b"), type};
|
||||
if (type = schema.marks.em)
|
||||
if ((type = schema.marks.em))
|
||||
i.toggleEm = {run: toggleMark(type), dom: icon("i"), type};
|
||||
if (type = schema.marks.link)
|
||||
if ((type = schema.marks.link))
|
||||
i.toggleLink = linkItem(type);
|
||||
|
||||
menu.items = i;
|
||||
|
|
|
@ -51,7 +51,7 @@ const basicSchema = {
|
|||
// This works around a Google Docs misbehavior where
|
||||
// pasted content will be inexplicably wrapped in `<b>`
|
||||
// tags with a font-weight normal.
|
||||
{tag: "b", getAttrs: node => node.style.fontWeight != "normal" && null},
|
||||
{tag: "b", getAttrs: node => node.style.fontWeight !== "normal" && null},
|
||||
{style: "font-weight", getAttrs: value => /^(bold(er)?|[5-9]\d{2,})$/.test(value) && null}],
|
||||
toDOM() { return ["strong", 0] }
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ const listSchema = {
|
|||
}
|
||||
}
|
||||
}
|
||||
const linkSchema = {
|
||||
const linkSchema = { // eslint-disable-line no-unused-vars
|
||||
marks: {
|
||||
link: {
|
||||
attrs: {
|
||||
|
|
|
@ -39,16 +39,14 @@ export default class Godo {
|
|||
case 'basic':
|
||||
displayBlocksMenu = false;
|
||||
return basic_schema;
|
||||
break;
|
||||
case 'headers':
|
||||
return headers_schema;
|
||||
break;
|
||||
case 'list':
|
||||
return list_schema
|
||||
case 'full':
|
||||
default:
|
||||
return full_schema
|
||||
};
|
||||
}
|
||||
})();
|
||||
|
||||
this.editor_wrapper = document.createElement('div');
|
||||
|
@ -81,7 +79,7 @@ export default class Godo {
|
|||
}
|
||||
});
|
||||
|
||||
this.textarea.form.addEventListener('submit', e => {
|
||||
this.textarea.form.addEventListener('submit', () => {
|
||||
textarea.value = this.getHTML();
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue