chore fix lint reduce errors generated (#83)

* add dep domhandler imported in in src/build/static

* lint and jsDoc error

* move domhandler to devDep

* chore: add package lock

* escape string jsDoc

* chore: add astro dep in until prism import is refactored

* chore: add snowpack example package lock
This commit is contained in:
duncanhealy 2021-04-12 16:20:58 +01:00 committed by GitHub
parent cffde0192b
commit 687ff5bacd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 270 additions and 697 deletions

File diff suppressed because it is too large Load diff

View file

@ -24,6 +24,7 @@
"@11ty/eleventy-plugin-syntaxhighlight": "^3.0.4",
"@contentful/rich-text-html-renderer": "^14.1.2",
"@contentful/rich-text-types": "^14.1.2",
"astro": "file:../../",
"eleventy-plugin-nesting-toc": "^1.2.0",
"luxon": "^1.25.0",
"markdown-it": "^12.0.2",

14
package-lock.json generated
View file

@ -1136,17 +1136,17 @@
"integrity": "sha512-LsTgx/L5VpD+Q8lmsXSHW2WpA+eBlZ9HPf3erD1IoPF00/3JKHZ3BknUVA2QGDNu69ZNmyFmCWBSO45XjYKC5w=="
},
"domhandler": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/domhandler/-/domhandler-4.0.0.tgz",
"integrity": "sha512-KPTbnGQ1JeEMQyO1iYXoagsI6so/C96HZiFyByU3T6iAzpXn8EGEvct6unm1ZGoed8ByO2oirxgwxBmqKF9haA==",
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/domhandler/-/domhandler-4.1.0.tgz",
"integrity": "sha512-/6/kmsGlMY4Tup/nGVutdrK9yQi4YjWVcVeoQmixpzjOUK1U7pQkvAPHBJeUxOgxF0J8f8lwCJSlCfD0V4CMGQ==",
"requires": {
"domelementtype": "^2.1.0"
"domelementtype": "^2.2.0"
},
"dependencies": {
"domelementtype": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/domelementtype/-/domelementtype-2.1.0.tgz",
"integrity": "sha512-LsTgx/L5VpD+Q8lmsXSHW2WpA+eBlZ9HPf3erD1IoPF00/3JKHZ3BknUVA2QGDNu69ZNmyFmCWBSO45XjYKC5w=="
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/domelementtype/-/domelementtype-2.2.0.tgz",
"integrity": "sha512-DtBMo82pv1dFtUmHyr48beiuq792Sxohr+8Hm9zoxklYPfa6n0Z3Byjj2IV7bmr2IyqClnqEQhfgHJJ5QF0R5A=="
}
}
},

View file

@ -82,6 +82,7 @@
"@typescript-eslint/eslint-plugin": "^4.18.0",
"@typescript-eslint/parser": "^4.18.0",
"concurrently": "^6.0.0",
"domhandler": "^4.1.0",
"eslint": "^7.22.0",
"eslint-config-prettier": "^8.1.0",
"eslint-plugin-prettier": "^3.3.1",

View file

@ -20,7 +20,9 @@ export function getAttrValue(attributes: Attribute[], name: string): string | un
export function setAttrValue(attributes: Attribute[], name: string, value: string): void {
const attr = attributes.find((a) => a.name === name);
if (attr) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
attr.value[0]!.data = value;
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
attr.value[0]!.raw = value;
}
}

View file

@ -147,17 +147,21 @@ export async function collectDynamicImports(filename: URL, { astroConfig, loggin
switch (defn.plugin) {
case 'preact': {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
imports.add(dynamic.get('preact')!);
rel = rel.replace(/\.[^.]+$/, '.js');
break;
}
case 'react': {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
imports.add(dynamic.get('react')!);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
imports.add(dynamic.get('react-dom')!);
rel = rel.replace(/\.[^.]+$/, '.js');
break;
}
case 'vue': {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
imports.add(dynamic.get('vue')!);
rel = rel.replace(/\.[^.]+$/, '.vue.js');
break;
@ -275,6 +279,7 @@ export async function bundle(imports: Set<string>, { runtime, dist }: BundleOpti
format: 'esm',
exports: 'named',
entryFileNames(chunk) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return chunk.facadeModuleId!.substr(1);
},
plugins: [

View file

@ -8,6 +8,7 @@ export function collectStatics(html: string) {
const $ = cheerio.load(html);
const append = (el: Element, attr: string) => {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const value: string = $(el).attr(attr)!;
if (value.startsWith('http')) {
return;

View file

@ -1,3 +1,4 @@
/* eslint-disable no-console */
import type { AstroConfig } from './@types/astro';
import * as colors from 'kleur/colors';
@ -90,6 +91,7 @@ export async function cli(args: string[]) {
}
case 'build':
case 'dev': {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const cmd = cmdMap.get(state)!;
runCommand(flags._[3], cmd);
}

View file

@ -381,9 +381,11 @@ function compileModule(module: Script, state: CodegenState, compileOptions: Comp
if (plugin) {
componentPlugins.add(plugin);
}
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
state.importExportStatements.add(module.content.slice(componentImport.start!, componentImport.end!));
}
for (const componentImport of componentExports) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
state.importExportStatements.add(module.content.slice(componentImport.start!, componentImport.end!));
}
@ -392,6 +394,7 @@ function compileModule(module: Script, state: CodegenState, compileOptions: Comp
for (const componentExport of componentProps) {
propsStatement += `${(componentExport.id as Identifier).name}`;
if (componentExport.init) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
propsStatement += `= ${babelGenerator(componentExport.init!).code}`;
}
propsStatement += `,`;
@ -482,7 +485,9 @@ function compileHtml(enterNode: TemplateNode, state: CodegenState, compileOption
switch (node.type) {
case 'Expression': {
let child = '';
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
if (node.children!.length) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
child = compileHtml(node.children![0], state, compileOptions);
}
let raw = node.codeStart + child + node.codeEnd;

View file

@ -21,6 +21,7 @@ export default function (_opts: { filename: string; fileID: string }): Transform
name: '!doctype',
type: 'Element',
};
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
parent.children!.splice(index, 0, dtNode);
hasDoctype = true;
}

View file

@ -56,6 +56,7 @@ function walkAstWithVisitors(tmpl: TemplateNode, collection: VisitorCollection)
walk(tmpl, {
enter(node, parent, key, index) {
if (collection.enter.has(node.type)) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const fns = collection.enter.get(node.type)!;
for (let fn of fns) {
fn.call(this, node, parent, key, index);
@ -64,6 +65,7 @@ function walkAstWithVisitors(tmpl: TemplateNode, collection: VisitorCollection)
},
leave(node, parent, key, index) {
if (collection.leave.has(node.type)) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const fns = collection.leave.get(node.type)!;
for (let fn of fns) {
fn.call(this, node, parent, key, index);

View file

@ -4,13 +4,13 @@ import { getAttrValue } from '../../ast.js';
const PRISM_IMPORT = `import Prism from 'astro/components/Prism.astro';\n`;
const prismImportExp = /import Prism from ['"]astro\/components\/Prism.astro['"]/;
/** escaping code samples that contain template string replacement parts, ${foo} or example. */
function escape(code: string) {
return code.replace(/[`$]/g, (match) => {
return '\\' + match;
});
}
/** default export - Transform prism */
export default function (module: Script): Transformer {
let usesPrism = false;

View file

@ -124,6 +124,7 @@ async function transformStyle(code: string, { type, filename, scopedClass, mode
const { default: tailwindcss } = await import('@tailwindcss/jit');
postcssPlugins.push(tailwindcss());
} catch (err) {
// eslint-disable-next-line no-console
console.error(err);
throw new Error(`tailwindcss not installed. Try running \`npm install tailwindcss\` and trying again.`);
}

View file

@ -66,6 +66,7 @@ export default async function dev(astroConfig: AstroConfig) {
});
server.listen(port, hostname, () => {
// eslint-disable-next-line no-console
console.log(`Server running at http://${hostname}:${port}/`);
});
}

View file

@ -1,3 +1,4 @@
/** Linked list */
export function link<T extends { next?: T; prev?: T }>(next: T, prev: T) {
prev.next = next;
if (next) next.prev = prev;

View file

@ -4,7 +4,7 @@ interface PageLocation {
fileURL: URL;
snowpackURL: string;
}
/** findAnyPage and return the _astro candidate for snowpack */
function findAnyPage(candidates: Array<string>, astroRoot: URL): PageLocation | false {
for (let candidate of candidates) {
const url = new URL(`./pages/${candidate}`, astroRoot);
@ -32,7 +32,7 @@ type SearchResult =
| {
statusCode: 404;
};
/** searchForPage - look for astro or md pages */
export function searchForPage(url: URL, astroRoot: URL): SearchResult {
const reqPath = decodeURI(url.pathname);
const base = reqPath.substr(1);

View file

@ -1,7 +1,7 @@
import { createRuntime } from '../lib/runtime.js';
import { loadConfig } from '../lib/config.js';
import * as assert from 'uvu/assert';
/** setup fixtures for tests */
export function setup(Suite, fixturePath) {
let runtime, setupError;

View file

@ -27,6 +27,7 @@ SnowpackDev.before(async () => {
try {
runtime = await createRuntime(astroConfig, { logging });
} catch (err) {
// eslint-disable-next-line no-console
console.error(err);
setupError = err;
}
@ -36,7 +37,7 @@ SnowpackDev.after(async () => {
process.chdir(cwd);
(await runtime) && runtime.shutdown();
});
/** create an iterator for all page files */
async function* allPageFiles(root) {
for (const filename of await readdir(root)) {
const fullpath = new URL(filename, root);
@ -49,7 +50,7 @@ async function* allPageFiles(root) {
}
}
}
/** create an iterator for all pages and yield the relative paths */
async function* allPages(root) {
for await (let fileURL of allPageFiles(root)) {
let bare = fileURL.pathname.replace(/\.(astro|md)$/, '').replace(/index$/, '');
@ -79,6 +80,7 @@ SnowpackDev('Can load every page', async () => {
}
if (failed.length > 0) {
// eslint-disable-next-line no-console
console.error(failed);
}
assert.equal(failed.length, 0, 'Failed pages');

View file

@ -1,5 +1,5 @@
import cheerio from 'cheerio';
/** load html */
export function doc(html) {
return cheerio.load(html);
}