Skip to content

Commit b56af8e

Browse files
committed
Prerelease linting
1 parent 8ea64c9 commit b56af8e

35 files changed

+654
-416
lines changed

src/cli/commands/crawl.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import { Flags, Args } from '@oclif/core';
22
import { LogLevel } from 'crawlee';
3-
import {
4-
Spidergram,
5-
Spider,
6-
EntityQuery,
7-
UniqueUrl,
8-
} from '../../index.js';
3+
import { Spidergram, Spider, EntityQuery, UniqueUrl } from '../../index.js';
94
import { QueryFragments } from '../../model/queries/query-fragments.js';
105
import { CLI, OutputLevel, SgCommand } from '../index.js';
116
import { filterUrl } from '../../tools/urls/filter-url.js';
@@ -44,10 +39,12 @@ export default class Crawl extends SgCommand {
4439
const sg = await Spidergram.load();
4540
const { argv: urls, flags } = await this.parse(Crawl);
4641

47-
const crawlTargets = [...sg.config.spider?.seed ?? [], ...urls ?? []];
42+
const crawlTargets = [...(sg.config.spider?.seed ?? []), ...(urls ?? [])];
4843

4944
if (crawlTargets.length == 0) {
50-
this.error('Crawl URLs must be provided via the command line, or via the configuration file.');
45+
this.error(
46+
'Crawl URLs must be provided via the command line, or via the configuration file.',
47+
);
5148
}
5249

5350
if (flags.verbose) {

src/cli/commands/go.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,15 @@ export default class Go extends SgCommand {
3333
const sg = await Spidergram.load();
3434
const { argv: urls, flags } = await this.parse(Go);
3535

36-
const crawlTargets: string[] = [...sg.config.spider?.seed ?? [], ...urls ?? []];
36+
const crawlTargets: string[] = [
37+
...(sg.config.spider?.seed ?? []),
38+
...(urls ?? []),
39+
];
3740

3841
if (crawlTargets.length == 0) {
39-
this.error('Crawl URLs must be provided via the command line, or via the configuration file.');
42+
this.error(
43+
'Crawl URLs must be provided via the command line, or via the configuration file.',
44+
);
4045
}
4146

4247
if (flags.erase) {
@@ -84,8 +89,14 @@ export default class Go extends SgCommand {
8489

8590
this.ux.action.start('Crawl reports');
8691
await r.run();
87-
this.log(`Saved ${(r.status.files.length === 1) ? '1 report' : r.status.files.length + ' reports'}`);
88-
r.status.files.map(file => this.log(` ${file}`))
92+
this.log(
93+
`Saved ${
94+
r.status.files.length === 1
95+
? '1 report'
96+
: r.status.files.length + ' reports'
97+
}`,
98+
);
99+
r.status.files.map(file => this.log(` ${file}`));
89100
}
90101

91102
// We should perform some kin of wrapup step here.

src/cli/commands/init.ts

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default class Initialize extends SgCommand {
2020
char: 'f',
2121
summary: 'Configuration file format',
2222
options: ['json', 'yaml', 'json5'],
23-
default: 'json5'
23+
default: 'json5',
2424
}),
2525
dbaddress: Flags.string({
2626
char: 'a',
@@ -60,8 +60,8 @@ export default class Initialize extends SgCommand {
6060
populate: Flags.boolean({
6161
char: 'p',
6262
summary: 'Populate the config file with common defaults',
63-
default: true
64-
})
63+
default: true,
64+
}),
6565
};
6666

6767
async run() {
@@ -71,22 +71,25 @@ export default class Initialize extends SgCommand {
7171

7272
if (sg.configFile) {
7373
// Is there already a config file? Prompt to ensure the user really wants to generate this.
74-
await CLI.confirm(`A configuration file already exists. Create one anyways?`)
75-
.then(confirmed => { if (!confirmed) this.exit(0); })
74+
await CLI.confirm(
75+
`A configuration file already exists. Create one anyways?`,
76+
).then(confirmed => {
77+
if (!confirmed) this.exit(0);
78+
});
7679
}
7780

7881
const settings: SpidergramConfig = {
7982
configVersion: this.config.version,
8083
storageDirectory: flags.storage,
81-
outputDirectory: flags.output,
84+
outputDirectory: flags.output,
8285
arango: {
8386
databaseName: flags.dbname,
8487
url: flags.dbaddress,
8588
auth: {
8689
username: flags.dbuser,
87-
password: flags.dbpass
88-
}
89-
}
90+
password: flags.dbpass,
91+
},
92+
},
9093
};
9194

9295
if (flags.populate) {
@@ -116,11 +119,11 @@ export default class Initialize extends SgCommand {
116119
configData = JSON.stringify(settings, undefined, 4);
117120
break;
118121

119-
case 'json5':
122+
case 'json5':
120123
configData = stringify(settings, undefined, 4);
121124
break;
122-
123-
case 'yaml':
125+
126+
case 'yaml':
124127
configData = dump(settings);
125128
break;
126129
}
@@ -129,42 +132,47 @@ export default class Initialize extends SgCommand {
129132
this.error("The configuration file couln't be generated.");
130133
}
131134

132-
await writeFile(filePath, configData)
133-
.then(() => this.log('Config file generated!'));
135+
await writeFile(filePath, configData).then(() =>
136+
this.log('Config file generated!'),
137+
);
134138
}
135139
}
136140

137141
type ArangoStatus = {
138-
error?: boolean,
139-
server: boolean,
140-
auth: boolean,
141-
db: boolean
142-
}
143-
144-
export async function testConnection(name: string, host: string, user: string, pass: string): Promise<ArangoStatus> {
142+
error?: boolean;
143+
server: boolean;
144+
auth: boolean;
145+
db: boolean;
146+
};
147+
148+
export async function testConnection(
149+
name: string,
150+
host: string,
151+
user: string,
152+
pass: string,
153+
): Promise<ArangoStatus> {
145154
const results = {
146155
error: true,
147156
server: true,
148157
auth: true,
149-
db: true
158+
db: true,
150159
};
151160

152161
const connection = await ArangoStore.open(undefined, {
153162
url: host,
154163
auth: {
155164
username: user,
156-
password: pass
157-
}
158-
})
159-
.catch(() => results);
165+
password: pass,
166+
},
167+
}).catch(() => results);
160168

161169
if ('error' in connection) {
162170
return Promise.resolve(connection);
163171
} else {
164172
return Promise.resolve({
165173
server: true,
166174
auth: true,
167-
db: true
168-
})
175+
db: true,
176+
});
169177
}
170178
}

src/cli/commands/report.ts

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import _ from 'lodash';
55
import { queryFilterFlag } from '../shared/index.js';
66
import { buildFilter } from '../shared/flag-query-tools.js';
77

8-
98
export default class DoReport extends SgCommand {
109
static summary = 'Build and save a crawl report';
1110

@@ -34,12 +33,12 @@ export default class DoReport extends SgCommand {
3433
output: Flags.string({
3534
char: 'o',
3635
summary: 'Output file type',
37-
options: ['csv', 'tsv', 'json', 'json5', 'xlsx', 'debug']
36+
options: ['csv', 'tsv', 'json', 'json5', 'xlsx', 'debug'],
3837
}),
3938
setting: Flags.string({
4039
char: 's',
4140
summary: 'Add custom report setting',
42-
multiple: true
41+
multiple: true,
4342
}),
4443
};
4544

@@ -69,7 +68,10 @@ export default class DoReport extends SgCommand {
6968
} else {
7069
const data: Record<string, unknown>[] = Object.entries(reports).map(
7170
([name, report]) => {
72-
const r = report instanceof ReportRunner ? report : new ReportRunner(report);
71+
const r =
72+
report instanceof ReportRunner
73+
? report
74+
: new ReportRunner(report);
7375
return {
7476
report: name,
7577
category: r.config.group,
@@ -93,7 +95,9 @@ export default class DoReport extends SgCommand {
9395

9496
const definition = sg.config.reports?.[args.report ?? ''];
9597
const report =
96-
definition instanceof ReportRunner ? definition : new ReportRunner(definition);
98+
definition instanceof ReportRunner
99+
? definition
100+
: new ReportRunner(definition);
97101

98102
if (flags.filter) {
99103
const filters: AqFilter[] = [];
@@ -110,11 +114,15 @@ export default class DoReport extends SgCommand {
110114
if (flags.name) report.config.name = flags.name;
111115
if (flags.path) report.config.settings.path = flags.path;
112116
for (const s of flags.setting ?? []) {
113-
_.set(report.config.settings, s.split('=').shift() ?? '', s.split('=').pop() ?? true);
117+
_.set(
118+
report.config.settings,
119+
s.split('=').shift() ?? '',
120+
s.split('=').pop() ?? true,
121+
);
114122
}
115123

116124
if (flags.output === 'debug') {
117-
this.ux.styledHeader('Report structure')
125+
this.ux.styledHeader('Report structure');
118126
this.ux.styledJSON(report.config);
119127
} else {
120128
if (flags.output) report.config.settings.type = flags.output;
@@ -126,11 +134,17 @@ export default class DoReport extends SgCommand {
126134

127135
this.ux.action.start('Running report');
128136
await report.run();
129-
this.log(`Saved ${(report.status.files.length === 1) ? '1 report' : report.status.files.length + ' reports'}`);
130-
report.status.files.map(file => this.log(` ${file}`))
137+
this.log(
138+
`Saved ${
139+
report.status.files.length === 1
140+
? '1 report'
141+
: report.status.files.length + ' reports'
142+
}`,
143+
);
144+
report.status.files.map(file => this.log(` ${file}`));
131145

132146
if (report.status.lastError) {
133-
this.log('At least one error was encountered during processing:')
147+
this.log('At least one error was encountered during processing:');
134148
this.log(report.status.lastError);
135149
}
136150
}

src/cli/shared/flags.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export const analysisFlags = {
9494
char: 'r',
9595
summary: 'Reprocess already-analyzed pages',
9696
allowNo: true,
97-
default: false
97+
default: false,
9898
}),
9999
site: Flags.boolean({
100100
char: 's',

src/config/defaults.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export const analyzePageDefaults: PageAnalysisOptions = {
114114
links: false,
115115
site: 'parsed.hostname',
116116
properties: {},
117-
patterns: []
117+
patterns: [],
118118
};
119119

120120
export const spidergramDefaults: SpidergramConfig = {

src/config/global-normalizer.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
import { UrlMutators, ParsedUrl } from '@autogram/url-tools';
22
import minimatch from 'minimatch';
33

4-
type urlStringProps = 'protocol' | 'subdomain' | 'domain' | 'host' | 'hostname' | 'pathname' | 'search' | 'hash';
4+
type urlStringProps =
5+
| 'protocol'
6+
| 'subdomain'
7+
| 'domain'
8+
| 'host'
9+
| 'hostname'
10+
| 'pathname'
11+
| 'search'
12+
| 'hash';
513

614
export interface NormalizerOptions {
715
/**
@@ -79,11 +87,13 @@ export function globalNormalizer(
7987
if (opts.forceLowercase) {
8088
if (opts.forceLowercase === true) {
8189
url.href = url.href.toLocaleLowerCase();
82-
}
83-
else {
84-
const props = Array.isArray(opts.forceLowercase) ? opts.forceLowercase : [opts.forceLowercase];
90+
} else {
91+
const props = Array.isArray(opts.forceLowercase)
92+
? opts.forceLowercase
93+
: [opts.forceLowercase];
8594
for (const prop of props) {
86-
url[prop as urlStringProps] = url[prop as urlStringProps].toLocaleLowerCase();
95+
url[prop as urlStringProps] =
96+
url[prop as urlStringProps].toLocaleLowerCase();
8797
}
8898
}
8999
}

src/config/spidergram-config.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ import {
77
PageContentOptions,
88
PageDataOptions,
99
} from '../tools/html/index.js';
10-
import {
11-
PageAnalysisOptions,
12-
} from '../tools/graph/analyze-page.js';
10+
import { PageAnalysisOptions } from '../tools/graph/analyze-page.js';
1311
import { TechAuditOptions } from '../tools/browser/index.js';
1412
import { Configuration as FileConfiguration } from 'typefs';
1513
import { Config as ArangoConfig } from 'arangojs/connection';
@@ -30,7 +28,6 @@ import { SpiderCli } from '../cli/shared/index.js';
3028
* get more precise contextual control.
3129
*/
3230
export interface SpidergramConfig extends Record<string, unknown> {
33-
3431
/**
3532
* The version of Spidergram the configuration data was originally created for.
3633
* This allows Spidergram to warn you if your config is out of date.

0 commit comments

Comments
 (0)