Curly braces linting fixes (#5585)

pull/5598/head
Ben McCann 5 years ago committed by GitHub
parent 7c1e6a6ce7
commit 7ea6a2994a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -521,8 +521,7 @@ export default class Component {
if (this.hoistable_nodes.has(node)) return false; if (this.hoistable_nodes.has(node)) return false;
if (this.reactive_declaration_nodes.has(node)) return false; if (this.reactive_declaration_nodes.has(node)) return false;
if (node.type === 'ImportDeclaration') return false; if (node.type === 'ImportDeclaration') return false;
if (node.type === 'ExportDeclaration' && node.specifiers.length > 0) if (node.type === 'ExportDeclaration' && node.specifiers.length > 0) return false;
return false;
return true; return true;
}); });
} }
@ -1038,8 +1037,9 @@ export default class Component {
this.vars.find( this.vars.find(
variable => variable.name === name && variable.module variable => variable.name === name && variable.module
) )
) ) {
return false; return false;
}
return true; return true;
}); });
@ -1288,8 +1288,9 @@ export default class Component {
declaration.dependencies.forEach(name => { declaration.dependencies.forEach(name => {
if (declaration.assignees.has(name)) return; if (declaration.assignees.has(name)) return;
const earlier_declarations = lookup.get(name); const earlier_declarations = lookup.get(name);
if (earlier_declarations) if (earlier_declarations) {
earlier_declarations.forEach(add_declaration); earlier_declarations.forEach(add_declaration);
}
}); });
this.reactive_declarations.push(declaration); this.reactive_declarations.push(declaration);
@ -1319,8 +1320,9 @@ export default class Component {
if (globals.has(name) && node.type !== 'InlineComponent') return; if (globals.has(name) && node.type !== 'InlineComponent') return;
let message = `'${name}' is not defined`; 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`; message += `. Consider adding a <script> block with 'export let ${name}' to declare a prop`;
}
this.warn(node, { this.warn(node, {
code: 'missing-declaration', code: 'missing-declaration',
@ -1382,8 +1384,9 @@ function process_component_options(component: Component, nodes) {
const message = "'tag' must be a string literal"; const message = "'tag' must be a string literal";
const tag = get_value(attribute, code, message); const tag = get_value(attribute, code, message);
if (typeof tag !== 'string' && tag !== null) if (typeof tag !== 'string' && tag !== null) {
component.error(attribute, { code, message }); component.error(attribute, { code, message });
}
if (tag && !/^[a-zA-Z][a-zA-Z0-9]*-[a-zA-Z0-9-]+$/.test(tag)) { if (tag && !/^[a-zA-Z][a-zA-Z0-9]*-[a-zA-Z0-9-]+$/.test(tag)) {
component.error(attribute, { component.error(attribute, {
@ -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 message = "The 'namespace' attribute must be a string literal representing a valid namespace";
const ns = get_value(attribute, code, message); const ns = get_value(attribute, code, message);
if (typeof ns !== 'string') if (typeof ns !== 'string') {
component.error(attribute, { code, message }); component.error(attribute, { code, message });
}
if (valid_namespaces.indexOf(ns) === -1) { if (valid_namespaces.indexOf(ns) === -1) {
const match = fuzzymatch(ns, valid_namespaces); const match = fuzzymatch(ns, valid_namespaces);
@ -1437,8 +1441,9 @@ function process_component_options(component: Component, nodes) {
const message = `${name} attribute must be true or false`; const message = `${name} attribute must be true or false`;
const value = get_value(attribute, code, message); const value = get_value(attribute, code, message);
if (typeof value !== 'boolean') if (typeof value !== 'boolean') {
component.error(attribute, { code, message }); component.error(attribute, { code, message });
}
component_options[name] = value; component_options[name] = value;
break; break;

@ -67,18 +67,22 @@ export default class Binding extends Node {
} else { } else {
const variable = component.var_lookup.get(name); const variable = component.var_lookup.get(name);
if (!variable || variable.global) component.error(this.expression.node, { if (!variable || variable.global) {
component.error(this.expression.node, {
code: 'binding-undeclared', code: 'binding-undeclared',
message: `${name} is not declared` message: `${name} is not declared`
}); });
}
variable[this.expression.node.type === 'MemberExpression' ? 'mutated' : 'reassigned'] = true; variable[this.expression.node.type === 'MemberExpression' ? 'mutated' : 'reassigned'] = true;
if (info.expression.type === 'Identifier' && !variable.writable) component.error(this.expression.node, { if (info.expression.type === 'Identifier' && !variable.writable) {
component.error(this.expression.node, {
code: 'invalid-binding', code: 'invalid-binding',
message: 'Cannot bind to a variable which is not writable' message: 'Cannot bind to a variable which is not writable'
}); });
} }
}
const type = parent.get_static_attribute_value('type'); const type = parent.get_static_attribute_value('type');

@ -48,9 +48,10 @@ export default class AttributeWrapper extends BaseAttributeWrapper {
// special case — <option value={foo}> — see below // special case — <option value={foo}> — see below
if (this.parent.node.name === 'option' && node.name === 'value') { if (this.parent.node.name === 'option' && node.name === 'value') {
let select: ElementWrapper = this.parent; 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 // @ts-ignore todo: doublecheck this, but looks to be correct
select = select.parent; select = select.parent;
}
if (select && select.select_binding_dependencies) { if (select && select.select_binding_dependencies) {
select.select_binding_dependencies.forEach(prop => { select.select_binding_dependencies.forEach(prop => {

@ -178,11 +178,12 @@ export class Parser {
} }
read_until(pattern: RegExp) { read_until(pattern: RegExp) {
if (this.index >= this.template.length) if (this.index >= this.template.length) {
this.error({ this.error({
code: 'unexpected-eof', code: 'unexpected-eof',
message: 'Unexpected end of input' message: 'Unexpected end of input'
}); });
}
const start = this.index; const start = this.index;
const match = pattern.exec(this.template.slice(start)); const match = pattern.exec(this.template.slice(start));

@ -32,10 +32,12 @@ export default function read_script(parser: Parser, start: number, attributes: N
const script_start = parser.index; const script_start = parser.index;
const script_end = parser.template.indexOf(script_closing_tag, script_start); const script_end = parser.template.indexOf(script_closing_tag, script_start);
if (script_end === -1) parser.error({ if (script_end === -1) {
parser.error({
code: 'unclosed-script', code: 'unclosed-script',
message: '<script> must have a closing tag' message: '<script> must have a closing tag'
}); });
}
const source = parser.template.slice(0, script_start).replace(/[^\n]/g, ' ') + const source = parser.template.slice(0, script_start).replace(/[^\n]/g, ' ') +
parser.template.slice(script_start, script_end); parser.template.slice(script_start, script_end);

@ -288,10 +288,12 @@ export default function mustache(parser: Parser) {
if (parser.eat(',')) { if (parser.eat(',')) {
parser.allow_whitespace(); parser.allow_whitespace();
block.index = parser.read_identifier(); block.index = parser.read_identifier();
if (!block.index) parser.error({ if (!block.index) {
parser.error({
code: 'expected-name', code: 'expected-name',
message: 'Expected name' message: 'Expected name'
}); });
}
parser.allow_whitespace(); parser.allow_whitespace();
} }

@ -13,8 +13,9 @@ const GRAM_SIZE_UPPER = 3;
// return an edit distance from 0 to 1 // return an edit distance from 0 to 1
function _distance(str1: string, str2: string) { function _distance(str1: string, str2: string) {
if (str1 === null && str2 === null) if (str1 === null && str2 === null) {
throw 'Trying to compare two null values'; throw 'Trying to compare two null values';
}
if (str1 === null || str2 === null) return 0; if (str1 === null || str2 === null) return 0;
str1 = String(str1); str1 = String(str1);
str2 = String(str2); str2 = String(str2);

@ -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])); tick_spring(ctx, last_value[i], current_value[i], target_value[i]));
} else if (typeof current_value === 'object') { } else if (typeof current_value === 'object') {
const next_value = {}; const next_value = {};
for (const k in current_value) for (const k in current_value) {
// @ts-ignore // @ts-ignore
next_value[k] = tick_spring(ctx, last_value[k], current_value[k], target_value[k]); next_value[k] = tick_spring(ctx, last_value[k], current_value[k], target_value[k]);
}
// @ts-ignore // @ts-ignore
return next_value; return next_value;
} else { } else {
@ -121,8 +122,9 @@ export function spring<T=any>(value?: T, opts: SpringOpts = {}): Spring<T> {
last_value = value; last_value = value;
store.set(value = next_value); store.set(value = next_value);
if (ctx.settled) if (ctx.settled) {
task = null; task = null;
}
return !ctx.settled; return !ctx.settled;
}); });
} }

@ -118,9 +118,11 @@ describe('hydration', () => {
throw err; throw err;
} }
if (config.show) showOutput(cwd, { if (config.show) {
showOutput(cwd, {
hydratable: true hydratable: true
}); });
}
}); });
} }

Loading…
Cancel
Save