Skip to content

Commit

Permalink
upgrade ESLint config (sveltejs#5472)
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann committed Sep 30, 2020
1 parent c24b313 commit 229a16d
Show file tree
Hide file tree
Showing 356 changed files with 993 additions and 993 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"posttest": "agadoo internal/index.mjs",
"prepublishOnly": "npm run lint && PUBLISH=true npm test",
"tsd": "tsc -p src/compiler --emitDeclarationOnly && tsc -p src/runtime --emitDeclarationOnly",
"lint": "eslint \"{src,test}/**/*.{ts,js}\""
"lint": "eslint '{src,test}/**/*.{ts,js}'"
},
"repository": {
"type": "git",
Expand All @@ -63,7 +63,7 @@
"@rollup/plugin-sucrase": "^3.0.0",
"@rollup/plugin-typescript": "^2.0.1",
"@rollup/plugin-virtual": "^2.0.0",
"@sveltejs/eslint-config": "github:sveltejs/eslint-config#v5.0.0",
"@sveltejs/eslint-config": "github:sveltejs/eslint-config#v5.2.0",
"@types/mocha": "^7.0.0",
"@types/node": "^8.10.53",
"@typescript-eslint/eslint-plugin": "^3.0.2",
Expand Down
50 changes: 25 additions & 25 deletions src/compiler/compile/Component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export default class Component {
) || { start: 0, end: 0 };
this.warn(svelteOptions, {
code: 'custom-element-no-tag',
message: `No custom element 'tag' option was specified. To automatically register a custom element, specify a name with a hyphen in it, e.g. <svelte:options tag="my-thing"/>. To hide this warning, use <svelte:options tag={null}/>`
message: 'No custom element \'tag\' option was specified. To automatically register a custom element, specify a name with a hyphen in it, e.g. <svelte:options tag="my-thing"/>. To hide this warning, use <svelte:options tag={null}/>'
});
}
this.tag = this.component_options.tag || compile_options.tag;
Expand Down Expand Up @@ -241,7 +241,7 @@ export default class Component {
const { compile_options, name } = this;
const { format = 'esm' } = compile_options;

const banner = `${this.file ? `${this.file} ` : ``}generated by Svelte v${'__VERSION__'}`;
const banner = `${this.file ? `${this.file} ` : ''}generated by Svelte v${'__VERSION__'}`;

const program: any = { type: 'Program', body: result.js };

Expand Down Expand Up @@ -458,16 +458,16 @@ export default class Component {
extract_exports(node) {
if (node.type === 'ExportDefaultDeclaration') {
this.error(node, {
code: `default-export`,
message: `A component cannot have a default export`
code: 'default-export',
message: 'A component cannot have a default export'
});
}

if (node.type === 'ExportNamedDeclaration') {
if (node.source) {
this.error(node, {
code: `not-implemented`,
message: `A component currently cannot have an export ... from`
code: 'not-implemented',
message: 'A component currently cannot have an export ... from'
});
}
if (node.declaration) {
Expand All @@ -478,7 +478,7 @@ export default class Component {
variable.export_name = name;
if (variable.writable && !(variable.referenced || variable.referenced_from_script || variable.subscribable)) {
this.warn(declarator, {
code: `unused-export-let`,
code: 'unused-export-let',
message: `${this.name.name} has unused export property '${name}'. If it is for external reference only, please consider using \`export const ${name}\``
});
}
Expand All @@ -501,7 +501,7 @@ export default class Component {

if (variable.writable && !(variable.referenced || variable.referenced_from_script || variable.subscribable)) {
this.warn(specifier, {
code: `unused-export-let`,
code: 'unused-export-let',
message: `${this.name.name} has unused export property '${specifier.exported.name}'. If it is for external reference only, please consider using \`export const ${specifier.exported.name}\``
});
}
Expand Down Expand Up @@ -550,7 +550,7 @@ export default class Component {
if (name[0] === '$') {
this.error(node as any, {
code: 'illegal-declaration',
message: `The $ prefix is reserved, and cannot be used for variable and import names`
message: 'The $ prefix is reserved, and cannot be used for variable and import names'
});
}

Expand All @@ -568,7 +568,7 @@ export default class Component {
if (name[0] === '$') {
this.error(node as any, {
code: 'illegal-subscription',
message: `Cannot reference store value inside <script context="module">`
message: 'Cannot reference store value inside <script context="module">'
});
} else {
this.add_var({
Expand Down Expand Up @@ -629,7 +629,7 @@ export default class Component {
if (name[0] === '$') {
this.error(node as any, {
code: 'illegal-declaration',
message: `The $ prefix is reserved, and cannot be used for variable and import names`
message: 'The $ prefix is reserved, and cannot be used for variable and import names'
});
}

Expand Down Expand Up @@ -867,8 +867,8 @@ export default class Component {

if (name[1] !== '$' && scope.has(name.slice(1)) && scope.find_owner(name.slice(1)) !== this.instance_scope) {
this.error(node, {
code: `contextual-store`,
message: `Stores must be declared at the top level of the component (this may change in a future version of Svelte)`
code: 'contextual-store',
message: 'Stores must be declared at the top level of the component (this may change in a future version of Svelte)'
});
}
}
Expand Down Expand Up @@ -935,7 +935,7 @@ export default class Component {
// TODO is this still true post-#3539?
component.error(declarator as any, {
code: 'destructured-prop',
message: `Cannot declare props in destructured declaration`
message: 'Cannot declare props in destructured declaration'
});
}

Expand Down Expand Up @@ -1379,23 +1379,23 @@ function process_component_options(component: Component, nodes) {
switch (name) {
case 'tag': {
const code = 'invalid-tag-attribute';
const message = `'tag' must be a string literal`;
const message = "'tag' must be a string literal";
const tag = get_value(attribute, code, message);

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, {
code: `invalid-tag-property`,
message: `tag name must be two or more words joined by the '-' character`
code: 'invalid-tag-property',
message: "tag name must be two or more words joined by the '-' character"
});
}

if (tag && !component.compile_options.customElement) {
component.warn(attribute, {
code: 'missing-custom-element-compile-options',
message: `The 'tag' option is used when generating a custom element. Did you forget the 'customElement: true' compile option?`
message: "The 'tag' option is used when generating a custom element. Did you forget the 'customElement: true' compile option?"
});
}

Expand All @@ -1405,7 +1405,7 @@ function process_component_options(component: Component, nodes) {

case 'namespace': {
const code = 'invalid-namespace-attribute';
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);

if (typeof ns !== 'string')
Expand All @@ -1415,12 +1415,12 @@ function process_component_options(component: Component, nodes) {
const match = fuzzymatch(ns, valid_namespaces);
if (match) {
component.error(attribute, {
code: `invalid-namespace-property`,
code: 'invalid-namespace-property',
message: `Invalid namespace '${ns}' (did you mean '${match}'?)`
});
} else {
component.error(attribute, {
code: `invalid-namespace-property`,
code: 'invalid-namespace-property',
message: `Invalid namespace '${ns}'`
});
}
Expand All @@ -1446,14 +1446,14 @@ function process_component_options(component: Component, nodes) {

default:
component.error(attribute, {
code: `invalid-options-attribute`,
message: `<svelte:options> unknown attribute`
code: 'invalid-options-attribute',
message: '<svelte:options> unknown attribute'
});
}
} else {
component.error(attribute, {
code: `invalid-options-attribute`,
message: `<svelte:options> can only have static 'tag', 'namespace', 'accessors', 'immutable' and 'preserveWhitespace' attributes`
code: 'invalid-options-attribute',
message: "<svelte:options> can only have static 'tag', 'namespace', 'accessors', 'immutable' and 'preserveWhitespace' attributes"
});
}
});
Expand Down
10 changes: 5 additions & 5 deletions src/compiler/compile/css/Selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ export default class Selector {
const selector = block.selectors[i];
if (selector.type === 'PseudoClassSelector' && selector.name === 'global') {
component.error(selector, {
code: `css-invalid-global`,
message: `:global(...) must be the first element in a compound selector`
code: 'css-invalid-global',
message: ':global(...) must be the first element in a compound selector'
});
}
}
Expand All @@ -139,8 +139,8 @@ export default class Selector {
for (let i = start; i < end; i += 1) {
if (this.blocks[i].global) {
component.error(this.blocks[i].selectors[0], {
code: `css-invalid-global`,
message: `:global(...) can be at the start or end of a selector sequence, but not in the middle`
code: 'css-invalid-global',
message: ':global(...) can be at the start or end of a selector sequence, but not in the middle'
});
}
}
Expand Down Expand Up @@ -286,7 +286,7 @@ function test_attribute(operator, expected_value, case_insensitive, value) {
case '^=': return value.startsWith(expected_value);
case '$=': return value.endsWith(expected_value);
case '*=': return value.includes(expected_value);
default: throw new Error(`this shouldn't happen`);
default: throw new Error("this shouldn't happen");
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/compiler/compile/css/Stylesheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Element from '../nodes/Element';
import { Ast } from '../../interfaces';
import Component from '../Component';
import { CssNode } from './interfaces';
import hash from "../utils/hash";
import hash from '../utils/hash';

function remove_css_prefix(name: string): string {
return name.replace(/^-((webkit)|(moz)|(o)|(ms))-/, '');
Expand Down Expand Up @@ -428,7 +428,7 @@ export default class Stylesheet {
this.children.forEach(child => {
child.warn_on_unused_selector((selector: Selector) => {
component.warn(selector.node, {
code: `css-unused-selector`,
code: 'css-unused-selector',
message: `Unused CSS selector "${this.source.slice(selector.node.start, selector.node.end)}"`
});
});
Expand Down
6 changes: 3 additions & 3 deletions src/compiler/compile/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ function validate_options(options: CompileOptions, warnings: Warning[]) {
}

if (name && /^[a-z]/.test(name)) {
const message = `options.name should be capitalised`;
const message = 'options.name should be capitalised';
warnings.push({
code: `options-lowercase-name`,
code: 'options-lowercase-name',
message,
filename,
toString: () => message
Expand All @@ -58,7 +58,7 @@ function validate_options(options: CompileOptions, warnings: Warning[]) {
if (loopGuardTimeout && !dev) {
const message = 'options.loopGuardTimeout is for options.dev = true only';
warnings.push({
code: `options-loop-guard-timeout`,
code: 'options-loop-guard-timeout',
message,
filename,
toString: () => message
Expand Down
8 changes: 4 additions & 4 deletions src/compiler/compile/nodes/Animation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ export default class Animation extends Node {

if (parent.animation) {
component.error(this, {
code: `duplicate-animation`,
message: `An element can only have one 'animate' directive`
code: 'duplicate-animation',
message: "An element can only have one 'animate' directive"
});
}

const block = parent.parent;
if (!block || block.type !== 'EachBlock' || !block.key) {
// TODO can we relax the 'immediate child' rule?
component.error(this, {
code: `invalid-animation`,
message: `An element that use the animate directive must be the immediate child of a keyed each block`
code: 'invalid-animation',
message: 'An element that use the animate directive must be the immediate child of a keyed each block'
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/compiler/compile/nodes/Binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import get_object from '../utils/get_object';
import Expression from './shared/Expression';
import Component from '../Component';
import TemplateScope from './shared/TemplateScope';
import {dimensions} from "../../utils/patterns";
import {dimensions} from '../../utils/patterns';
import { Node as ESTreeNode } from 'estree';

// TODO this should live in a specific binding
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/compile/nodes/EachBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ export default class EachBlock extends AbstractBlock {
if (this.children.length !== 1) {
const child = this.children.find(child => !!(child as Element).animation);
component.error((child as Element).animation, {
code: `invalid-animation`,
message: `An element that use the animate directive must be the sole child of a keyed each block`
code: 'invalid-animation',
message: 'An element that use the animate directive must be the sole child of a keyed each block'
});
}
}
Expand Down
Loading

0 comments on commit 229a16d

Please sign in to comment.