1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-29 18:09:49 +02:00

Enforce 2-spaces indentation

This commit is contained in:
Soreine
2016-11-10 11:03:51 +01:00
parent 094cdf8a51
commit a319499f7c
20 changed files with 328 additions and 334 deletions

View File

@@ -38,6 +38,7 @@
"import/no-named-as-default": "error", "import/no-named-as-default": "error",
"import/no-named-as-default-member": "error", "import/no-named-as-default-member": "error",
"import/no-unresolved": "error", "import/no-unresolved": "error",
"indent": ["error", 2],
"key-spacing": ["error", { "beforeColon": false, "afterColon": true }], "key-spacing": ["error", { "beforeColon": false, "afterColon": true }],
"lines-around-comment": ["error", { "beforeBlockComment": true, "afterBlockComment": true }], "lines-around-comment": ["error", { "beforeBlockComment": true, "afterBlockComment": true }],
"new-parens": "error", "new-parens": "error",

View File

@@ -83,7 +83,7 @@ const INLINE_CHILDREN_RULE = {
const { nodes } = inline const { nodes } = inline
const invalids = nodes.filter(n => n.kind != 'inline' && n.kind != 'text') const invalids = nodes.filter(n => n.kind != 'inline' && n.kind != 'text')
return invalids.size ? invalids : null return invalids.size ? invalids : null
}, },
normalize: (transform, inline, invalids) => { normalize: (transform, inline, invalids) => {
return invalids.reduce((t, n) => t.removeNodeByKey(n.key, { normalize: false }), transform) return invalids.reduce((t, n) => t.removeNodeByKey(n.key, { normalize: false }), transform)
} }

View File

@@ -21,13 +21,12 @@ function block(value) {
switch (typeOf(value)) { switch (typeOf(value)) {
case 'string': case 'string':
case 'object': { case 'object':
return Block.create(nodeProperties(value)) return Block.create(nodeProperties(value))
}
default: { default:
throw new Error(`Invalid \`block\` argument! It must be a block, an object, or a string. You passed: "${value}".`) throw new Error(`Invalid \`block\` argument! It must be a block, an object, or a string. You passed: "${value}".`)
} }
}
} }
/** /**
@@ -42,13 +41,12 @@ function inline(value) {
switch (typeOf(value)) { switch (typeOf(value)) {
case 'string': case 'string':
case 'object': { case 'object':
return Inline.create(nodeProperties(value)) return Inline.create(nodeProperties(value))
}
default: { default:
throw new Error(`Invalid \`inline\` argument! It must be an inline, an object, or a string. You passed: "${value}".`) throw new Error(`Invalid \`inline\` argument! It must be an inline, an object, or a string. You passed: "${value}".`)
} }
}
} }
/** /**
@@ -82,13 +80,12 @@ function mark(value) {
switch (typeOf(value)) { switch (typeOf(value)) {
case 'string': case 'string':
case 'object': { case 'object':
return Mark.create(markProperties(value)) return Mark.create(markProperties(value))
}
default: { default:
throw new Error(`Invalid \`mark\` argument! It must be a mark, an object, or a string. You passed: "${value}".`) throw new Error(`Invalid \`mark\` argument! It must be a mark, an object, or a string. You passed: "${value}".`)
} }
}
} }
/** /**
@@ -102,11 +99,11 @@ function markProperties(value = {}) {
const ret = {} const ret = {}
switch (typeOf(value)) { switch (typeOf(value)) {
case 'string': { case 'string':
ret.type = value ret.type = value
break break
}
case 'object': { case 'object':
for (const k in value) { for (const k in value) {
if (k == 'data') { if (k == 'data') {
if (value[k] !== undefined) ret[k] = Data.create(value[k]) if (value[k] !== undefined) ret[k] = Data.create(value[k])
@@ -115,11 +112,10 @@ function markProperties(value = {}) {
} }
} }
break break
}
default: { default:
throw new Error(`Invalid mark \`properties\` argument! It must be an object, a string or a mark. You passed: "${value}".`) throw new Error(`Invalid mark \`properties\` argument! It must be an object, a string or a mark. You passed: "${value}".`)
} }
}
return ret return ret
} }
@@ -135,11 +131,11 @@ function nodeProperties(value = {}) {
const ret = {} const ret = {}
switch (typeOf(value)) { switch (typeOf(value)) {
case 'string': { case 'string':
ret.type = value ret.type = value
break break
}
case 'object': { case 'object':
if (value.isVoid !== undefined) ret.isVoid = !!value.isVoid if (value.isVoid !== undefined) ret.isVoid = !!value.isVoid
for (const k in value) { for (const k in value) {
if (k == 'data') { if (k == 'data') {
@@ -149,11 +145,10 @@ function nodeProperties(value = {}) {
} }
} }
break break
}
default: { default:
throw new Error(`Invalid node \`properties\` argument! It must be an object, a string or a node. You passed: "${value}".`) throw new Error(`Invalid node \`properties\` argument! It must be an object, a string or a node. You passed: "${value}".`)
} }
}
return ret return ret
} }
@@ -169,13 +164,12 @@ function selection(value) {
if (value instanceof Selection) return value if (value instanceof Selection) return value
switch (typeOf(value)) { switch (typeOf(value)) {
case 'object': { case 'object':
return Selection.create(value) return Selection.create(value)
}
default: { default:
throw new Error(`Invalid \`selection\` argument! It must be a selection or an object. You passed: "${value}".`) throw new Error(`Invalid \`selection\` argument! It must be a selection or an object. You passed: "${value}".`)
} }
}
} }
/** /**
@@ -189,7 +183,7 @@ function selectionProperties(value = {}) {
const ret = {} const ret = {}
switch (typeOf(value)) { switch (typeOf(value)) {
case 'object': { case 'object':
if (value.anchorKey !== undefined) ret.anchorKey = value.anchorKey if (value.anchorKey !== undefined) ret.anchorKey = value.anchorKey
if (value.anchorOffset !== undefined) ret.anchorOffset = value.anchorOffset if (value.anchorOffset !== undefined) ret.anchorOffset = value.anchorOffset
if (value.focusKey !== undefined) ret.focusKey = value.focusKey if (value.focusKey !== undefined) ret.focusKey = value.focusKey
@@ -198,11 +192,10 @@ function selectionProperties(value = {}) {
if (value.isFocused !== undefined) ret.isFocused = !!value.isFocused if (value.isFocused !== undefined) ret.isFocused = !!value.isFocused
if (value.marks !== undefined) ret.marks = value.marks if (value.marks !== undefined) ret.marks = value.marks
break break
}
default: { default:
throw new Error(`Invalid selection \`properties\` argument! It must be an object or a selection. You passed: "${value}".`) throw new Error(`Invalid selection \`properties\` argument! It must be an object or a selection. You passed: "${value}".`)
} }
}
return ret return ret
} }