From 28b160f2fc4659cab3252a64a9cc83514e26c3f4 Mon Sep 17 00:00:00 2001 From: pushkine Date: Mon, 18 May 2020 12:57:38 +0200 Subject: [PATCH] lint --- .eslintrc.js | 12 +++--- package.json | 5 ++- src/ambient.ts | 1 + src/compiler/compile/render_dom/Block.ts | 2 +- src/compiler/compile/render_dom/invalidate.ts | 2 +- .../wrappers/InlineComponent/index.ts | 2 +- src/runtime/.eslintrc.json | 5 +++ src/runtime/environment/index.ts | 2 +- src/runtime/internal/Component.ts | 4 +- src/runtime/internal/dom.ts | 4 +- src/runtime/internal/stores.ts | 8 ++-- test/.eslintrc.json | 8 ++-- test/hydration/index.ts | 16 ++++---- test/runtime/ambient.ts | 8 ---- test/runtime/index.ts | 1 - test/test.ts | 3 +- test/tiny-glob.ts | 39 ++++++++++--------- 17 files changed, 61 insertions(+), 61 deletions(-) create mode 100644 src/runtime/.eslintrc.json delete mode 100644 test/runtime/ambient.ts diff --git a/.eslintrc.js b/.eslintrc.js index 93ca1623fe..4ab5e224d2 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -15,30 +15,28 @@ module.exports = { 'no-var': 2, 'no-unreachable': 2, 'valid-typeof': 2, - 'quote-props': [2, 'as-needed'], + 'quote-props': 'off', 'prefer-arrow-callback': 2, 'prefer-const': [2, { destructuring: 'all' }], 'arrow-spacing': 2, 'no-inner-declarations': 0, 'require-atomic-updates': 'off', + '@typescript-eslint/no-empty-function': 'off', + '@typescript-eslint/ban-ts-ignore': 'off', + '@typescript-eslint/no-this-alias': 'off', '@typescript-eslint/indent': 'off', '@typescript-eslint/camelcase': 'off', '@typescript-eslint/no-use-before-define': 'off', '@typescript-eslint/explicit-function-return-type': 'off', '@typescript-eslint/no-explicit-any': 'off', '@typescript-eslint/explicit-member-accessibility': 'off', - '@typescript-eslint/no-unused-vars': [ - 'error', - { - argsIgnorePattern: '^_', - }, - ], '@typescript-eslint/no-object-literal-type-assertion': 'off', '@typescript-eslint/no-unused-vars': 'off', '@typescript-eslint/prefer-interface': 'off', }, globals: { globalThis: false, + __VERSION__: true, }, env: { es6: true, diff --git a/package.json b/package.json index c10a06daee..080acc08de 100644 --- a/package.json +++ b/package.json @@ -82,9 +82,9 @@ "code-red": "0.1.1", "codecov": "^3.6.5", "css-tree": "1.0.0-alpha22", - "eslint": "^7.0.0", "eslint-plugin-import": "^2.20.2", "eslint-plugin-svelte3": "^2.7.3", + "eslint": "^7.0.0", "esm": "^3.2.25", "estree-walker": "^2.0.1", "is-reference": "^1.1.4", @@ -96,8 +96,9 @@ "periscopic": "^2.0.1", "puppeteer": "^3.0.4", "rollup": "^2.10.2", - "source-map": "^0.7.3", "source-map-support": "^0.5.19", + "source-map": "^0.7.3", + "tiny-glob": "^0.2.6", "ts-mocha": "^7.0.0", "tslib": "^2.0.0", "typescript": "^3.9.2" diff --git a/src/ambient.ts b/src/ambient.ts index 7853694bda..663f991411 100644 --- a/src/ambient.ts +++ b/src/ambient.ts @@ -1 +1,2 @@ +/* eslint-disable no-var */ declare var __VERSION__: string; diff --git a/src/compiler/compile/render_dom/Block.ts b/src/compiler/compile/render_dom/Block.ts index 6ef51f58c0..9183972196 100644 --- a/src/compiler/compile/render_dom/Block.ts +++ b/src/compiler/compile/render_dom/Block.ts @@ -454,7 +454,7 @@ export default class Block { : fn; } - render_listeners(chunk: string = '') { + render_listeners(chunk = '') { if (this.event_listeners.length > 0) { const dispose: Identifier = { type: 'Identifier', diff --git a/src/compiler/compile/render_dom/invalidate.ts b/src/compiler/compile/render_dom/invalidate.ts index f07bbc7546..567bfd010a 100644 --- a/src/compiler/compile/render_dom/invalidate.ts +++ b/src/compiler/compile/render_dom/invalidate.ts @@ -10,7 +10,7 @@ export function invalidate( scope: Scope, node: Node, names: Set, - main_execution_context: boolean = false + main_execution_context = false ) { const { component } = renderer; diff --git a/src/compiler/compile/render_dom/wrappers/InlineComponent/index.ts b/src/compiler/compile/render_dom/wrappers/InlineComponent/index.ts index 0da5928d89..ae4abcb036 100644 --- a/src/compiler/compile/render_dom/wrappers/InlineComponent/index.ts +++ b/src/compiler/compile/render_dom/wrappers/InlineComponent/index.ts @@ -337,7 +337,7 @@ export default class InlineComponentWrapper extends Wrapper { } const params = [x`#value`]; - let args = []; + const args = []; contextual_dependencies.forEach((name) => { params.push({ type: 'Identifier', name }); renderer.add_to_context(name, true); diff --git a/src/runtime/.eslintrc.json b/src/runtime/.eslintrc.json new file mode 100644 index 0000000000..5c10f73e26 --- /dev/null +++ b/src/runtime/.eslintrc.json @@ -0,0 +1,5 @@ +{ + "rules": { + "import/no-unresolved": "off" + } +} diff --git a/src/runtime/environment/index.ts b/src/runtime/environment/index.ts index 7dbeeed0ee..9d02f1ee55 100644 --- a/src/runtime/environment/index.ts +++ b/src/runtime/environment/index.ts @@ -12,7 +12,7 @@ export const is_cors = } })(); export const has_Symbol = typeof Symbol === 'function'; - +/* eslint-disable no-var */ declare var global: any; export const globals = is_browser ? window : typeof globalThis !== 'undefined' ? globalThis : global; export const resolved_promise = Promise.resolve(); diff --git a/src/runtime/internal/Component.ts b/src/runtime/internal/Component.ts index 1c7d1d3e07..23bba43066 100644 --- a/src/runtime/internal/Component.ts +++ b/src/runtime/internal/Component.ts @@ -44,8 +44,8 @@ export function bind({ $$: { props, bound, ctx } }, name: string, callback: (pro export function mount_component({ $$ }, target, anchor) { if ($$.fragment) $$.fragment.m(target, anchor); add_render_callback(() => { - let { on_mount, on_destroy, after_update } = $$, - i = 0, + const { on_mount, on_destroy, after_update } = $$; + let i = 0, res; for (; i < on_mount.length; i++) if ('function' === typeof (res = on_mount[i]())) diff --git a/src/runtime/internal/dom.ts b/src/runtime/internal/dom.ts index 088ad25288..48aebb0594 100644 --- a/src/runtime/internal/dom.ts +++ b/src/runtime/internal/dom.ts @@ -184,7 +184,9 @@ export function set_input_value(input, value) { export function set_input_type(input, type) { try { input.type = type; - } catch (e) {} + } catch (e) { + // + } } export function set_style(node, property, value, is_important?) { diff --git a/src/runtime/internal/stores.ts b/src/runtime/internal/stores.ts index 2fd98c6276..54d125ae60 100644 --- a/src/runtime/internal/stores.ts +++ b/src/runtime/internal/stores.ts @@ -155,13 +155,13 @@ const parseStructure = ( ): initCreateMotionTick | initCreateTweenTick => { const isArray = Array.isArray(obj); if (typeof obj === 'object' && obj !== null && (isArray || Object.prototype === Object.getPrototypeOf(obj))) { - const keys = Object.keys(obj); let i = 0, - l = keys.length, k = '', - createTickers = keys.map((key) => parseStructure(obj[key], schema)((next_value) => (obj[key] = next_value))), - tickers = new Array(l), pending = 0; + const keys = Object.keys(obj), + l = keys.length, + createTickers = keys.map((key) => parseStructure(obj[key], schema)((next_value) => (obj[key] = next_value))), + tickers = new Array(l); const target = { ...obj }; obj = isArray ? [...(obj as T[])] : { ...obj }; return (set) => (_, to_value) => { diff --git a/test/.eslintrc.json b/test/.eslintrc.json index d5ba8f9d9c..fc5735de83 100644 --- a/test/.eslintrc.json +++ b/test/.eslintrc.json @@ -1,5 +1,7 @@ { - "rules": { - "no-console": "off" - } + "rules": { + "no-console": "off", + "@typescript-eslint/no-var-requires": "off", + "@typescript-eslint/no-namespace": "off" + } } diff --git a/test/hydration/index.ts b/test/hydration/index.ts index e4b7f02388..a5262c1b99 100644 --- a/test/hydration/index.ts +++ b/test/hydration/index.ts @@ -51,13 +51,11 @@ describe('hydration', () => { try { global.window = window; - let SvelteComponent; - - try { - SvelteComponent = require(`${cwd}/main.svelte`).default; - } catch (err) { - throw err; - } + // try { + const SvelteComponent = require(`${cwd}/main.svelte`).default; + // } catch (err) { + // throw err; + // } const target = window.document.body; const head = window.document.head; @@ -68,7 +66,9 @@ describe('hydration', () => { try { before_head = fs.readFileSync(`${cwd}/_before_head.html`, 'utf-8'); head.innerHTML = before_head; - } catch (err) {} + } catch (_err) { + // + } const snapshot = config.snapshot ? config.snapshot(target) : {}; diff --git a/test/runtime/ambient.ts b/test/runtime/ambient.ts deleted file mode 100644 index f1db83b413..0000000000 --- a/test/runtime/ambient.ts +++ /dev/null @@ -1,8 +0,0 @@ -type Test = { - test({ assert, component, mod, target, window, raf, compileOptions }): void | Promise; - html: string; - skip: boolean; -}; -declare module 'samples/*/_config.js' { - export default Test; -} diff --git a/test/runtime/index.ts b/test/runtime/index.ts index 0780152cf7..45e38c344a 100644 --- a/test/runtime/index.ts +++ b/test/runtime/index.ts @@ -4,7 +4,6 @@ import { rollup } from 'rollup'; import virtual from '@rollup/plugin-virtual'; import { clear_loops, flush, SvelteComponent } from '../../internal'; import { set_now, set_raf, set_framerate } from '../../environment'; -import './ambient'; import { showOutput, loadConfig, loadSvelte, cleanRequireCache, env, setupHtmlEqual, mkdirp } from '../helpers'; import { glob } from '../tiny-glob'; import { assert } from '../test'; diff --git a/test/test.ts b/test/test.ts index 0ca222084d..bfd01e490f 100644 --- a/test/test.ts +++ b/test/test.ts @@ -1,8 +1,7 @@ import './ambient'; import * as assert$1 from 'assert'; -import { readFileSync } from 'fs'; export const assert = (assert$1 as unknown) as typeof assert$1 & { htmlEqual: (actual, expected, message?) => void }; -const { glob } = require('./tiny-glob.ts'); +import { glob } from './tiny-glob'; // require('./setup.ts'); diff --git a/test/tiny-glob.ts b/test/tiny-glob.ts index 39a3a77d79..b9097a9038 100644 --- a/test/tiny-glob.ts +++ b/test/tiny-glob.ts @@ -14,17 +14,17 @@ const GLOBSTAR = `((?:[^/]*(?:/|$))*)`; const WILDCARD = `([^/]*)`; const GLOBSTAR_SEGMENT = `((?:[^${SEP_ESC}]*(?:${SEP_ESC}|$))*)`; const WILDCARD_SEGMENT = `([^${SEP_ESC}]*)`; -const isHidden = /(^|[\\\/])\.[^\\\/\.]/g; +const isHidden = /(^|[\\/])\.[^\\/.]/g; let CACHE = {}; function isglob(str, { strict = true } = {}) { if (str === '') return false; - let match, - rgx = strict ? STRICT : RELAXED; + let match; + const rgx = strict ? STRICT : RELAXED; while ((match = rgx.exec(str))) { if (match[2]) return true; let idx = match.index + match[0].length; - let open = match[1]; - let close = open ? CHARS[open] : null; + const open = match[1]; + const close = open ? CHARS[open] : null; let n; if (open && close) if ((n = str.indexOf(close, idx)) !== -1) idx = n + 1; str = str.slice(idx); @@ -33,15 +33,15 @@ function isglob(str, { strict = true } = {}) { } function parent(str, { strict = false } = {}) { str = normalize(str).replace(/\/|\\/, '/'); - if (/[\{\[].*[\/]*.*[\}\]]$/.test(str)) str += '/'; + if (/[{[].*[/]*.*[}]]$/.test(str)) str += '/'; str += 'a'; do str = dirname(str); - while (isglob(str, { strict }) || /(^|[^\\])([\{\[]|\([^\)]+$)/.test(str)); - return str.replace(/\\([\*\?\|\[\]\(\)\{\}])/g, '$1'); + while (isglob(str, { strict }) || /(^|[^\\])([{[]|\([^)]+$)/.test(str)); + return str.replace(/\\([*?|[\](){}])/g, '$1'); } function globalyzer(pattern, opts = {}) { let base = parent(pattern, opts); - let isGlob = isglob(pattern, opts); + const isGlob = isglob(pattern, opts); let glob; if (base != '.') { if ((glob = pattern.substr(base.length)).startsWith('/')) glob = glob.substr(1); @@ -54,7 +54,7 @@ function globalyzer(pattern, opts = {}) { function globrex(glob, { extended = false, globstar = false, strict = false, filepath = false, flags = '' } = {}) { let regex = ''; let segment = ''; - let path = { + const path = { regex: '', segments: [], globstar: undefined, @@ -101,7 +101,7 @@ function globrex(glob, { extended = false, globstar = false, strict = false, fil case ')': { if (ext.length) { add(c); - let type = ext.pop(); + const type = ext.pop(); if (type === '@') { add('{1}'); } else if (type === '!') { @@ -177,16 +177,16 @@ function globrex(glob, { extended = false, globstar = false, strict = false, fil ext.push(c); break; } - let prevChar = glob[i - 1]; + const prevChar = glob[i - 1]; let starCount = 1; while (glob[i + 1] === '*') { starCount++; i++; } - let nextChar = glob[i + 1]; + const nextChar = glob[i + 1]; if (!globstar) add('.*'); else { - let isGlobstar = + const isGlobstar = starCount > 1 && (prevChar === '/' || prevChar === void 0) && (nextChar === '/' || nextChar === void 0); if (isGlobstar) { add(GLOBSTAR, { only: 'regex' }); @@ -225,8 +225,9 @@ function walk(output, prefix, lexer, filesOnly, dot, cwd, dirname = '', level = const dir = join(cwd, prefix, dirname); const files = readdirSync(dir); let i = 0, - len = files.length, file; + const len = files.length; + let fullpath, relpath, stats, isMatch; for (; i < len; i++) { fullpath = join(dir, (file = files[i])); @@ -245,11 +246,11 @@ function walk(output, prefix, lexer, filesOnly, dot, cwd, dirname = '', level = } export function glob(str: string, { cwd = '.', absolute = false, filesOnly = false, dot = false, flush = false }) { if (!str) return []; - let glob = globalyzer(str); + const glob = globalyzer(str); if (!glob.isGlob) { try { - let resolved = resolve(cwd, str); - let dirent = statSync(resolved); + const resolved = resolve(cwd, str); + const dirent = statSync(resolved); if (filesOnly && !dirent.isFile()) return []; return absolute ? [resolved] : [str]; @@ -260,7 +261,7 @@ export function glob(str: string, { cwd = '.', absolute = false, filesOnly = fal } } if (flush) CACHE = {}; - let matches = []; + const matches = []; const { path } = globrex(glob.glob, { filepath: true, globstar: true, extended: true }); //@ts-ignore path.globstar = path.globstar.toString();