Fix linter errors and warnings (#1218)
* fix lint issues, enable lint in ci * add changeset
This commit is contained in:
parent
9482fadeb8
commit
44fb8ebcc4
12 changed files with 33 additions and 26 deletions
5
.changeset/thirty-ads-destroy.md
Normal file
5
.changeset/thirty-ads-destroy.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Remove non-null assertions, fix lint issues and enable lint in CI.
|
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
|
@ -95,8 +95,6 @@ jobs:
|
||||||
|
|
||||||
- name: Lint
|
- name: Lint
|
||||||
run: yarn lint
|
run: yarn lint
|
||||||
# linting is currently not passing, so just do this for inline for now
|
|
||||||
continue-on-error: true
|
|
||||||
|
|
||||||
smoke:
|
smoke:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
|
@ -101,7 +101,7 @@ function mergeCLIFlags(astroConfig: AstroConfig, flags: CLIState['options']) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Handle `astro run` command */
|
/** 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 {
|
try {
|
||||||
const projectRoot = options.projectRoot || rawRoot;
|
const projectRoot = options.projectRoot || rawRoot;
|
||||||
const astroConfig = await loadConfig(projectRoot, options.config);
|
const astroConfig = await loadConfig(projectRoot, options.config);
|
||||||
|
|
|
@ -223,7 +223,7 @@ function getComponentWrapper(_name: string, hydration: HydrationAttributes, { ur
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let metadata: string = '';
|
let metadata = '';
|
||||||
if (method) {
|
if (method) {
|
||||||
const componentUrl = getComponentUrl(astroConfig, url, pathToFileURL(filename));
|
const componentUrl = getComponentUrl(astroConfig, url, pathToFileURL(filename));
|
||||||
const componentExport = getComponentExport();
|
const componentExport = getComponentExport();
|
||||||
|
|
|
@ -82,13 +82,15 @@ export class EndOfHead {
|
||||||
}
|
}
|
||||||
|
|
||||||
private appendToHead(...nodes: TemplateNode[]) {
|
private appendToHead(...nodes: TemplateNode[]) {
|
||||||
const head = this.head!;
|
if (this.head) {
|
||||||
|
const head = this.head;
|
||||||
head.children = head.children ?? [];
|
head.children = head.children ?? [];
|
||||||
head.children.push(...nodes);
|
head.children.push(...nodes);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private prependToFirstNonHead(...nodes: TemplateNode[]) {
|
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);
|
this.parent?.children?.splice(idx, 0, ...nodes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -138,7 +138,7 @@ export class ConfigManager {
|
||||||
async buildSource(contents: string): Promise<string> {
|
async buildSource(contents: string): Promise<string> {
|
||||||
const renderers = await this.buildRendererInstances();
|
const renderers = await this.buildRendererInstances();
|
||||||
const rendererServerPackages = renderers.map(({ server }) => server);
|
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 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)))));
|
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> {
|
private async importModule(snowpackRuntime: SnowpackServerRuntime): Promise<void> {
|
||||||
await snowpackRuntime!.importModule(CONFIG_MODULE_URL);
|
await snowpackRuntime.importModule(CONFIG_MODULE_URL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,10 +14,12 @@ export default async function onMedia(astroId: string, options: HydrateOptions,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const mql = matchMedia(options.value!);
|
if (options.value) {
|
||||||
|
const mql = matchMedia(options.value);
|
||||||
if (mql.matches) {
|
if (mql.matches) {
|
||||||
cb();
|
cb();
|
||||||
} else {
|
} else {
|
||||||
mql.addEventListener('change', cb, { once: true });
|
mql.addEventListener('change', cb, { once: true });
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@ export function setRenderers(_rendererInstances: RendererInstance[]) {
|
||||||
rendererInstances = ([] as RendererInstance[]).concat(_rendererInstances);
|
rendererInstances = ([] as RendererInstance[]).concat(_rendererInstances);
|
||||||
}
|
}
|
||||||
|
|
||||||
function isCustomElementTag(name: string | Function) {
|
function isCustomElementTag(name: unknown) {
|
||||||
return typeof name === 'string' && /-/.test(name);
|
return typeof name === 'string' && /-/.test(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ async function resolveRenderer(Component: any, props: any = {}, children?: strin
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rendererCache.has(Component)) {
|
if (rendererCache.has(Component)) {
|
||||||
return rendererCache.get(Component)!;
|
return rendererCache.get(Component);
|
||||||
}
|
}
|
||||||
|
|
||||||
const errors: Error[] = [];
|
const errors: Error[] = [];
|
||||||
|
|
|
@ -26,7 +26,7 @@ class AstroElementRegistry {
|
||||||
|
|
||||||
findCached(tagName: string) {
|
findCached(tagName: string) {
|
||||||
if (this.cache.has(tagName)) {
|
if (this.cache.has(tagName)) {
|
||||||
return this.cache.get(tagName)!;
|
return this.cache.get(tagName);
|
||||||
}
|
}
|
||||||
let specifier = this.find(tagName);
|
let specifier = this.find(tagName);
|
||||||
if (specifier) {
|
if (specifier) {
|
||||||
|
|
|
@ -47,7 +47,7 @@ export interface LogOptions {
|
||||||
level?: LoggerLevel;
|
level?: LoggerLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const defaultLogOptions: LogOptions = {
|
export const defaultLogOptions: Required<LogOptions> = {
|
||||||
dest: defaultLogDestination,
|
dest: defaultLogDestination,
|
||||||
level: 'info',
|
level: 'info',
|
||||||
};
|
};
|
||||||
|
@ -69,8 +69,8 @@ const levels: Record<LoggerLevel, number> = {
|
||||||
|
|
||||||
/** Full logging API */
|
/** Full logging API */
|
||||||
export function log(opts: LogOptions = {}, level: LoggerLevel, type: string | null, ...args: Array<any>) {
|
export function log(opts: LogOptions = {}, level: LoggerLevel, type: string | null, ...args: Array<any>) {
|
||||||
const logLevel = opts.level ?? defaultLogOptions.level!;
|
const logLevel = opts.level ?? defaultLogOptions.level;
|
||||||
const dest = opts.dest ?? defaultLogOptions.dest!;
|
const dest = opts.dest ?? defaultLogOptions.dest;
|
||||||
const event: LogMessage = {
|
const event: LogMessage = {
|
||||||
type,
|
type,
|
||||||
level,
|
level,
|
||||||
|
|
|
@ -150,9 +150,9 @@ function countOccurrences(needle: string, haystack: string) {
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isSpread(path: string) {
|
function isSpread(str: string) {
|
||||||
const spreadPattern = /\[\.{3}/g;
|
const spreadPattern = /\[\.{3}/g;
|
||||||
return spreadPattern.test(path);
|
return spreadPattern.test(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
function comparator(a: Item, b: Item) {
|
function comparator(a: Item, b: Item) {
|
||||||
|
|
|
@ -116,9 +116,9 @@ async function load(config: AstroRuntimeConfig, rawPathname: string | undefined)
|
||||||
return { statusCode: 404, error: new Error('No matching route found.') };
|
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 routeLocation = convertMatchToLocation(routeMatch, config.astroConfig);
|
||||||
const params = getParams(routeMatch.params)(paramsMatch);
|
const params = paramsMatch ? getParams(routeMatch.params)(paramsMatch) : {};
|
||||||
let pageProps = {} as Record<string, any>;
|
let pageProps = {} as Record<string, any>;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in a new issue