Skip to content
Merged
Prev Previous commit
Next Next commit
set indent lint rule as error and ignore outliers
  • Loading branch information
43081j committed Jun 6, 2019
commit 5cc47a5db8d92ea3288ed13ed2e55117eb54ad73
5 changes: 4 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
"prefer-const": [2, { "destructuring": "all" }],
"arrow-spacing": 2,
"no-inner-declarations": 0,
"@typescript-eslint/indent": ["warn", "tab", { "SwitchCase": 1 }],
"@typescript-eslint/indent": ["error", "tab", {
"SwitchCase": 1,
"ignoredNodes": ["TemplateLiteral"]
}],
"@typescript-eslint/camelcase": "off",
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/array-type": ["error", "array-simple"],
Expand Down
2 changes: 2 additions & 0 deletions src/compiler/compile/render-dom/Block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ export default class Block {
`);
}

/* eslint-disable @typescript-eslint/indent,indent */
return deindent`
${this.variables.size > 0 &&
`var ${Array.from(this.variables.keys())
Expand All @@ -374,6 +375,7 @@ export default class Block {
`.replace(/(#+)(\w*)/g, (_match: string, sigil: string, name: string) => {
return sigil === '#' ? this.alias(name) : sigil.slice(1) + name;
});
/* eslint-enable @typescript-eslint/indent,indent */
}

render_listeners(chunk: string = '') {
Expand Down
4 changes: 3 additions & 1 deletion src/compiler/compile/render-dom/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export default function dom(
const props = component.vars.filter(variable => !variable.module && variable.export_name);
const writable_props = props.filter(variable => variable.writable);

/* eslint-disable @typescript-eslint/indent,indent */
const set = (uses_props || writable_props.length > 0 || component.slots.size > 0)
? deindent`
${$$props} => {
Expand All @@ -86,6 +87,7 @@ export default function dom(
}
`
: null;
/* eslint-enable @typescript-eslint/indent,indent */

const body = [];

Expand Down Expand Up @@ -369,7 +371,7 @@ export default function dom(
})
.map(n => `$$dirty.${n}`).join(' || ');

let snippet = `[${d.node.body.start}-${d.node.end}]`;
let snippet = `[✂${d.node.body.start}-${d.node.end}✂]`;
if (condition) snippet = `if (${condition}) { ${snippet} }`;

if (condition || uses_props) {
Expand Down
6 changes: 5 additions & 1 deletion src/compiler/compile/render-dom/wrappers/IfBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,15 @@ export default class IfBlockWrapper extends Wrapper {
const current_block_type = block.get_unique_name(`current_block_type`);
const current_block_type_and = has_else ? '' : `${current_block_type} && `;

/* eslint-disable @typescript-eslint/indent,indent */
block.builders.init.add_block(deindent`
function ${select_block_type}(ctx) {
${this.branches
.map(({ condition, block }) => `${condition ? `if (${condition}) ` : ''}return ${block.name};`)
.join('\n')}
}
`);
/* eslint-enable @typescript-eslint/indent,indent */

block.builders.init.add_block(deindent`
var ${current_block_type} = ${select_block_type}(ctx);
Expand Down Expand Up @@ -283,6 +285,7 @@ export default class IfBlockWrapper extends Wrapper {
block.add_variable(current_block_type_index);
block.add_variable(name);

/* eslint-disable @typescript-eslint/indent,indent */
block.builders.init.add_block(deindent`
var ${if_block_creators} = [
${this.branches.map(branch => branch.block.name).join(',\n')}
Expand All @@ -297,6 +300,7 @@ export default class IfBlockWrapper extends Wrapper {
${!has_else && `return -1;`}
}
`);
/* eslint-enable @typescript-eslint/indent,indent */

if (has_else) {
block.builders.init.add_block(deindent`
Expand Down Expand Up @@ -429,7 +433,7 @@ export default class IfBlockWrapper extends Wrapper {
}
`;

// no `p()` here we don't want to update outroing nodes,
// no `p()` here — we don't want to update outroing nodes,
// as that will typically result in glitching
const exit = branch.block.has_outro_method
? deindent`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,13 @@ export default class InlineComponentWrapper extends Wrapper {
.filter((attribute: Attribute) => attribute.is_dynamic)
.forEach((attribute: Attribute) => {
if (attribute.dependencies.size > 0) {
/* eslint-disable @typescript-eslint/indent,indent */
updates.push(deindent`
if (${[...attribute.dependencies]
.map(dependency => `changed.${dependency}`)
.join(' || ')}) ${name_changes}${quote_prop_if_necessary(attribute.name)} = ${attribute.get_value(block)};
`);
/* eslint-enable @typescript-eslint/indent,indent */
}
});
}
Expand All @@ -262,7 +264,7 @@ export default class InlineComponentWrapper extends Wrapper {
let object;

if (binding.is_contextual && binding.expression.node.type === 'Identifier') {
// bind:x={y} we can't just do `y = x`, we need to
// bind:x={y} — we can't just do `y = x`, we need to
// to `array[index] = x;
const { name } = binding.expression.node;
const { snippet } = block.bindings.get(name);
Expand Down Expand Up @@ -316,7 +318,7 @@ export default class InlineComponentWrapper extends Wrapper {
let lhs = component.source.slice(binding.expression.node.start, binding.expression.node.end).trim();

if (binding.is_contextual && binding.expression.node.type === 'Identifier') {
// bind:x={y} we can't just do `y = x`, we need to
// bind:x={y} — we can't just do `y = x`, we need to
// to `array[index] = x;
const { name } = binding.expression.node;
const { object, property, snippet } = block.bindings.get(name);
Expand Down