Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Curly braces linting fixes #5585

Merged
merged 1 commit into from
Oct 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions src/compiler/compile/Component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -521,8 +521,7 @@ export default class Component {
if (this.hoistable_nodes.has(node)) return false;
if (this.reactive_declaration_nodes.has(node)) return false;
if (node.type === 'ImportDeclaration') return false;
if (node.type === 'ExportDeclaration' && node.specifiers.length > 0)
return false;
if (node.type === 'ExportDeclaration' && node.specifiers.length > 0) return false;
return true;
});
}
Expand Down Expand Up @@ -1038,8 +1037,9 @@ export default class Component {
this.vars.find(
variable => variable.name === name && variable.module
)
)
) {
return false;
}

return true;
});
Expand Down Expand Up @@ -1288,8 +1288,9 @@ export default class Component {
declaration.dependencies.forEach(name => {
if (declaration.assignees.has(name)) return;
const earlier_declarations = lookup.get(name);
if (earlier_declarations)
if (earlier_declarations) {
earlier_declarations.forEach(add_declaration);
}
});

this.reactive_declarations.push(declaration);
Expand Down Expand Up @@ -1319,8 +1320,9 @@ export default class Component {
if (globals.has(name) && node.type !== 'InlineComponent') return;

let message = `'${name}' is not defined`;
if (!this.ast.instance)
if (!this.ast.instance) {
message += `. Consider adding a <script> block with 'export let ${name}' to declare a prop`;
}

this.warn(node, {
code: 'missing-declaration',
Expand Down Expand Up @@ -1382,8 +1384,9 @@ function process_component_options(component: Component, nodes) {
const message = "'tag' must be a string literal";
const tag = get_value(attribute, code, message);

if (typeof tag !== 'string' && tag !== null)
if (typeof tag !== 'string' && tag !== null) {
component.error(attribute, { code, message });
}

if (tag && !/^[a-zA-Z][a-zA-Z0-9]*-[a-zA-Z0-9-]+$/.test(tag)) {
component.error(attribute, {
Expand All @@ -1408,8 +1411,9 @@ function process_component_options(component: Component, nodes) {
const message = "The 'namespace' attribute must be a string literal representing a valid namespace";
const ns = get_value(attribute, code, message);

if (typeof ns !== 'string')
if (typeof ns !== 'string') {
component.error(attribute, { code, message });
}

if (valid_namespaces.indexOf(ns) === -1) {
const match = fuzzymatch(ns, valid_namespaces);
Expand Down Expand Up @@ -1437,8 +1441,9 @@ function process_component_options(component: Component, nodes) {
const message = `${name} attribute must be true or false`;
const value = get_value(attribute, code, message);

if (typeof value !== 'boolean')
if (typeof value !== 'boolean') {
component.error(attribute, { code, message });
}

component_options[name] = value;
break;
Expand Down
20 changes: 12 additions & 8 deletions src/compiler/compile/nodes/Binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,21 @@ export default class Binding extends Node {
} else {
const variable = component.var_lookup.get(name);

if (!variable || variable.global) component.error(this.expression.node, {
code: 'binding-undeclared',
message: `${name} is not declared`
});
if (!variable || variable.global) {
component.error(this.expression.node, {
code: 'binding-undeclared',
message: `${name} is not declared`
});
}

variable[this.expression.node.type === 'MemberExpression' ? 'mutated' : 'reassigned'] = true;

if (info.expression.type === 'Identifier' && !variable.writable) component.error(this.expression.node, {
code: 'invalid-binding',
message: 'Cannot bind to a variable which is not writable'
});
if (info.expression.type === 'Identifier' && !variable.writable) {
component.error(this.expression.node, {
code: 'invalid-binding',
message: 'Cannot bind to a variable which is not writable'
});
}
}

const type = parent.get_static_attribute_value('type');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ export default class AttributeWrapper extends BaseAttributeWrapper {
// special case — <option value={foo}> — see below
if (this.parent.node.name === 'option' && node.name === 'value') {
let select: ElementWrapper = this.parent;
while (select && (select.node.type !== 'Element' || select.node.name !== 'select'))
while (select && (select.node.type !== 'Element' || select.node.name !== 'select')) {
// @ts-ignore todo: doublecheck this, but looks to be correct
select = select.parent;
}

if (select && select.select_binding_dependencies) {
select.select_binding_dependencies.forEach(prop => {
Expand Down
3 changes: 2 additions & 1 deletion src/compiler/parse/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,12 @@ export class Parser {
}

read_until(pattern: RegExp) {
if (this.index >= this.template.length)
if (this.index >= this.template.length) {
this.error({
code: 'unexpected-eof',
message: 'Unexpected end of input'
});
}

const start = this.index;
const match = pattern.exec(this.template.slice(start));
Expand Down
10 changes: 6 additions & 4 deletions src/compiler/parse/read/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ export default function read_script(parser: Parser, start: number, attributes: N
const script_start = parser.index;
const script_end = parser.template.indexOf(script_closing_tag, script_start);

if (script_end === -1) parser.error({
code: 'unclosed-script',
message: '<script> must have a closing tag'
});
if (script_end === -1) {
parser.error({
code: 'unclosed-script',
message: '<script> must have a closing tag'
});
}

const source = parser.template.slice(0, script_start).replace(/[^\n]/g, ' ') +
parser.template.slice(script_start, script_end);
Expand Down
10 changes: 6 additions & 4 deletions src/compiler/parse/state/mustache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,12 @@ export default function mustache(parser: Parser) {
if (parser.eat(',')) {
parser.allow_whitespace();
block.index = parser.read_identifier();
if (!block.index) parser.error({
code: 'expected-name',
message: 'Expected name'
});
if (!block.index) {
parser.error({
code: 'expected-name',
message: 'Expected name'
});
}

parser.allow_whitespace();
}
Expand Down
3 changes: 2 additions & 1 deletion src/compiler/utils/fuzzymatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ const GRAM_SIZE_UPPER = 3;

// return an edit distance from 0 to 1
function _distance(str1: string, str2: string) {
if (str1 === null && str2 === null)
if (str1 === null && str2 === null) {
throw 'Trying to compare two null values';
}
if (str1 === null || str2 === null) return 0;
str1 = String(str1);
str2 = String(str2);
Expand Down
6 changes: 4 additions & 2 deletions src/runtime/motion/spring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ function tick_spring<T>(ctx: TickContext<T>, last_value: T, current_value: T, ta
tick_spring(ctx, last_value[i], current_value[i], target_value[i]));
} else if (typeof current_value === 'object') {
const next_value = {};
for (const k in current_value)
for (const k in current_value) {
// @ts-ignore
next_value[k] = tick_spring(ctx, last_value[k], current_value[k], target_value[k]);
}
// @ts-ignore
return next_value;
} else {
Expand Down Expand Up @@ -121,8 +122,9 @@ export function spring<T=any>(value?: T, opts: SpringOpts = {}): Spring<T> {
last_value = value;
store.set(value = next_value);

if (ctx.settled)
if (ctx.settled) {
task = null;
}
return !ctx.settled;
});
}
Expand Down
8 changes: 5 additions & 3 deletions test/hydration/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,11 @@ describe('hydration', () => {
throw err;
}

if (config.show) showOutput(cwd, {
hydratable: true
});
if (config.show) {
showOutput(cwd, {
hydratable: true
});
}
});
}

Expand Down