Fix linter errors and warnings (#1218)

* fix lint issues, enable lint in ci

* add changeset
This commit is contained in:
Mihkel Eidast 2021-08-24 22:50:24 +03:00 committed by GitHub
parent 9482fadeb8
commit 44fb8ebcc4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 33 additions and 26 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Remove non-null assertions, fix lint issues and enable lint in CI.

View file

@ -95,8 +95,6 @@ jobs:
- name: Lint
run: yarn lint
# linting is currently not passing, so just do this for inline for now
continue-on-error: true
smoke:
runs-on: ubuntu-latest
@ -139,4 +137,4 @@ jobs:
- name: "Smoke Test: Build 'www'"
run: yarn build
working-directory: ./www
working-directory: ./www

View file

@ -101,7 +101,7 @@ function mergeCLIFlags(astroConfig: AstroConfig, flags: CLIState['options']) {
}
/** Handle `astro run` command */
async function runCommand(rawRoot: string, cmd: (a: AstroConfig, options: any) => Promise<void>, options: CLIState['options']) {
async function runCommand(rawRoot: string, cmd: (a: AstroConfig, opts: any) => Promise<void>, options: CLIState['options']) {
try {
const projectRoot = options.projectRoot || rawRoot;
const astroConfig = await loadConfig(projectRoot, options.config);

View file

@ -223,7 +223,7 @@ function getComponentWrapper(_name: string, hydration: HydrationAttributes, { ur
}
};
let metadata: string = '';
let metadata = '';
if (method) {
const componentUrl = getComponentUrl(astroConfig, url, pathToFileURL(filename));
const componentExport = getComponentExport();

View file

@ -82,13 +82,15 @@ export class EndOfHead {
}
private appendToHead(...nodes: TemplateNode[]) {
const head = this.head!;
head.children = head.children ?? [];
head.children.push(...nodes);
if (this.head) {
const head = this.head;
head.children = head.children ?? [];
head.children.push(...nodes);
}
}
private prependToFirstNonHead(...nodes: TemplateNode[]) {
let idx: number = this.parent?.children!.indexOf(this.firstNonHead!) || 0;
let idx: number = (this.firstNonHead && this.parent?.children?.indexOf(this.firstNonHead)) || 0;
this.parent?.children?.splice(idx, 0, ...nodes);
}
}

View file

@ -138,7 +138,7 @@ export class ConfigManager {
async buildSource(contents: string): Promise<string> {
const renderers = await this.buildRendererInstances();
const rendererServerPackages = renderers.map(({ server }) => server);
const rendererClientPackages = await Promise.all(renderers.filter(({ client }) => client).map(({ client }) => this.resolvePackageUrl(client!)));
const rendererClientPackages = await Promise.all(renderers.filter((instance): instance is RendererInstance & { client: string } => !!instance.client).map(({ client }) => this.resolvePackageUrl(client)));
const rendererPolyfills = await Promise.all(renderers.map(({ polyfills }) => Promise.all(polyfills.map((src) => this.resolvePackageUrl(src)))));
const rendererHydrationPolyfills = await Promise.all(renderers.map(({ hydrationPolyfills }) => Promise.all(hydrationPolyfills.map((src) => this.resolvePackageUrl(src)))));
@ -173,6 +173,6 @@ ${contents}
}
private async importModule(snowpackRuntime: SnowpackServerRuntime): Promise<void> {
await snowpackRuntime!.importModule(CONFIG_MODULE_URL);
await snowpackRuntime.importModule(CONFIG_MODULE_URL);
}
}

View file

@ -14,10 +14,12 @@ export default async function onMedia(astroId: string, options: HydrateOptions,
}
};
const mql = matchMedia(options.value!);
if (mql.matches) {
cb();
} else {
mql.addEventListener('change', cb, { once: true });
if (options.value) {
const mql = matchMedia(options.value);
if (mql.matches) {
cb();
} else {
mql.addEventListener('change', cb, { once: true });
}
}
}

View file

@ -45,7 +45,7 @@ export function setRenderers(_rendererInstances: RendererInstance[]) {
rendererInstances = ([] as RendererInstance[]).concat(_rendererInstances);
}
function isCustomElementTag(name: string | Function) {
function isCustomElementTag(name: unknown) {
return typeof name === 'string' && /-/.test(name);
}
@ -90,7 +90,7 @@ async function resolveRenderer(Component: any, props: any = {}, children?: strin
}
if (rendererCache.has(Component)) {
return rendererCache.get(Component)!;
return rendererCache.get(Component);
}
const errors: Error[] = [];

View file

@ -26,7 +26,7 @@ class AstroElementRegistry {
findCached(tagName: string) {
if (this.cache.has(tagName)) {
return this.cache.get(tagName)!;
return this.cache.get(tagName);
}
let specifier = this.find(tagName);
if (specifier) {

View file

@ -47,7 +47,7 @@ export interface LogOptions {
level?: LoggerLevel;
}
export const defaultLogOptions: LogOptions = {
export const defaultLogOptions: Required<LogOptions> = {
dest: defaultLogDestination,
level: 'info',
};
@ -69,8 +69,8 @@ const levels: Record<LoggerLevel, number> = {
/** Full logging API */
export function log(opts: LogOptions = {}, level: LoggerLevel, type: string | null, ...args: Array<any>) {
const logLevel = opts.level ?? defaultLogOptions.level!;
const dest = opts.dest ?? defaultLogOptions.dest!;
const logLevel = opts.level ?? defaultLogOptions.level;
const dest = opts.dest ?? defaultLogOptions.dest;
const event: LogMessage = {
type,
level,

View file

@ -150,9 +150,9 @@ function countOccurrences(needle: string, haystack: string) {
return count;
}
function isSpread(path: string) {
function isSpread(str: string) {
const spreadPattern = /\[\.{3}/g;
return spreadPattern.test(path);
return spreadPattern.test(str);
}
function comparator(a: Item, b: Item) {

View file

@ -116,9 +116,9 @@ async function load(config: AstroRuntimeConfig, rawPathname: string | undefined)
return { statusCode: 404, error: new Error('No matching route found.') };
}
const paramsMatch = routeMatch.pattern.exec(reqPath)!;
const paramsMatch = routeMatch.pattern.exec(reqPath);
const routeLocation = convertMatchToLocation(routeMatch, config.astroConfig);
const params = getParams(routeMatch.params)(paramsMatch);
const params = paramsMatch ? getParams(routeMatch.params)(paramsMatch) : {};
let pageProps = {} as Record<string, any>;
try {