Skip to content

Commit 39ebae6

Browse files
committed
refactor: rename files to match convention (#693)
I found snake-case easier to read, and given that the project doesn't use OOP a lot, having all PascalCase names doesn't reflect the paradigm and feels unnatural.
1 parent f7dfdcf commit 39ebae6

File tree

107 files changed

+499
-412
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+499
-412
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ type IssueFilter = IssueMatch | IssuePredicate | (IssueMatch | IssuePredicate)[]
139139

140140
| Name | Type | Default value | Description |
141141
| --------- | ------------- | ------------- | ----------- |
142-
| `include` | `IssueFilter` | `undefined` | If `object`, defines issue properties that should be [matched](./src/issue/IssueMatch.ts). If `function`, acts as a predicate where `issue` is an argument. |
142+
| `include` | `IssueFilter` | `undefined` | If `object`, defines issue properties that should be [matched](src/issue/issue-match.ts). If `function`, acts as a predicate where `issue` is an argument. |
143143
| `exclude` | `IssueFilter` | `undefined` | Same as `include` but issues that match this predicate will be excluded. |
144144

145145
<details>

release.config.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ module.exports = {
3232
[
3333
'@semantic-release/exec',
3434
{
35-
prepareCmd:
36-
"sed -i 's/{{VERSION}}/${nextRelease.version}/g' lib/ForkTsCheckerWebpackPlugin.js",
35+
prepareCmd: "sed -i 's/{{VERSION}}/${nextRelease.version}/g' lib/plugin.js",
3736
},
3837
],
3938
],

src/ForkTsCheckerWebpackPluginConfiguration.ts

-34
This file was deleted.

src/files-change.ts

+28-16
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import type * as webpack from 'webpack';
22

3-
import subtract from './utils/array/substract';
4-
import unique from './utils/array/unique';
5-
63
interface FilesChange {
74
changedFiles?: string[];
85
deletedFiles?: string[];
@@ -14,6 +11,12 @@ function getFilesChange(compiler: webpack.Compiler): FilesChange {
1411
return compilerFilesChangeMap.get(compiler) || { changedFiles: [], deletedFiles: [] };
1512
}
1613

14+
function consumeFilesChange(compiler: webpack.Compiler): FilesChange {
15+
const change = getFilesChange(compiler);
16+
clearFilesChange(compiler);
17+
return change;
18+
}
19+
1720
function updateFilesChange(compiler: webpack.Compiler, change: FilesChange): void {
1821
compilerFilesChangeMap.set(compiler, aggregateFilesChanges([getFilesChange(compiler), change]));
1922
}
@@ -29,22 +32,31 @@ function clearFilesChange(compiler: webpack.Compiler): void {
2932
* @returns Files change that represents all subsequent changes as a one event
3033
*/
3134
function aggregateFilesChanges(changes: FilesChange[]): FilesChange {
32-
let changedFiles: string[] = [];
33-
let deletedFiles: string[] = [];
34-
35-
for (const change of changes) {
36-
changedFiles = unique(
37-
subtract(changedFiles, change.deletedFiles).concat(change.changedFiles || [])
38-
);
39-
deletedFiles = unique(
40-
subtract(deletedFiles, change.changedFiles).concat(change.deletedFiles || [])
41-
);
35+
const changedFilesSet = new Set<string>();
36+
const deletedFilesSet = new Set<string>();
37+
38+
for (const { changedFiles = [], deletedFiles = [] } of changes) {
39+
for (const changedFile of changedFiles) {
40+
changedFilesSet.add(changedFile);
41+
deletedFilesSet.delete(changedFile);
42+
}
43+
for (const deletedFile of deletedFiles) {
44+
changedFilesSet.delete(deletedFile);
45+
deletedFilesSet.add(deletedFile);
46+
}
4247
}
4348

4449
return {
45-
changedFiles,
46-
deletedFiles,
50+
changedFiles: Array.from(changedFilesSet),
51+
deletedFiles: Array.from(deletedFilesSet),
4752
};
4853
}
4954

50-
export { FilesChange, getFilesChange, updateFilesChange, clearFilesChange, aggregateFilesChanges };
55+
export {
56+
FilesChange,
57+
getFilesChange,
58+
consumeFilesChange,
59+
updateFilesChange,
60+
clearFilesChange,
61+
aggregateFilesChanges,
62+
};

src/formatter/BasicFormatter.ts renamed to src/formatter/basic-formatter.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import chalk from 'chalk';
22

3-
import type { Formatter } from './Formatter';
3+
import type { Formatter } from './formatter';
44

55
function createBasicFormatter(): Formatter {
66
return function basicFormatter(issue) {

src/formatter/CodeFrameFormatter.ts renamed to src/formatter/code-frame-formatter.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import os from 'os';
33
import { codeFrameColumns } from '@babel/code-frame';
44
import fs from 'fs-extra';
55

6-
import { createBasicFormatter } from './BasicFormatter';
7-
import type { Formatter } from './Formatter';
6+
import { createBasicFormatter } from './basic-formatter';
7+
import type { Formatter } from './formatter';
88
import { BabelCodeFrameOptions } from './types/babel__code-frame';
99

1010
function createCodeFrameFormatter(options?: BabelCodeFrameOptions): Formatter {
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
import { createBasicFormatter } from './BasicFormatter';
2-
import { createCodeFrameFormatter } from './CodeFrameFormatter';
3-
import type { Formatter } from './Formatter';
4-
import type { CodeframeFormatterOptions, FormatterOptions } from './FormatterOptions';
1+
import { createBasicFormatter } from './basic-formatter';
2+
import { createCodeFrameFormatter } from './code-frame-formatter';
3+
import type { Formatter } from './formatter';
4+
import type { CodeframeFormatterOptions, FormatterOptions } from './formatter-options';
55

6-
type FormatterConfiguration = Formatter;
6+
type FormatterConfig = Formatter;
77

8-
function createFormatterConfiguration(
9-
options: FormatterOptions | undefined
10-
): FormatterConfiguration {
8+
function createFormatterConfig(options: FormatterOptions | undefined): FormatterConfig {
119
if (typeof options === 'function') {
1210
return options;
1311
}
@@ -23,16 +21,16 @@ function createFormatterConfiguration(
2321
}
2422

2523
if (type === 'codeframe') {
26-
const configuration =
24+
const config =
2725
options && typeof options === 'object'
2826
? (options as CodeframeFormatterOptions).options || {}
2927
: {};
30-
return createCodeFrameFormatter(configuration);
28+
return createCodeFrameFormatter(config);
3129
}
3230

3331
throw new Error(
3432
`Unknown "${type}" formatter. Available types are: "basic", "codeframe" or a custom function.`
3533
);
3634
}
3735

38-
export { FormatterConfiguration, createFormatterConfiguration };
36+
export { FormatterConfig, createFormatterConfig };

src/formatter/FormatterOptions.ts renamed to src/formatter/formatter-options.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Formatter } from './Formatter';
1+
import type { Formatter } from './formatter';
22
import type { BabelCodeFrameOptions } from './types/babel__code-frame';
33

44
type FormatterType = 'basic' | 'codeframe';
File renamed without changes.

src/formatter/index.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
export * from './Formatter';
2-
export * from './BasicFormatter';
3-
export * from './CodeFrameFormatter';
4-
export * from './WebpackFormatter';
5-
export * from './FormatterOptions';
6-
export * from './FormatterConfiguration';
1+
export * from './formatter';
2+
export * from './basic-formatter';
3+
export * from './code-frame-formatter';
4+
export * from './webpack-formatter';
5+
export * from './formatter-options';
6+
export * from './formatter-config';

src/formatter/WebpackFormatter.ts renamed to src/formatter/webpack-formatter.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import os from 'os';
33
import chalk from 'chalk';
44

55
import { formatIssueLocation } from '../issue';
6-
import { relativeToContext } from '../utils/path/relativeToContext';
6+
import { relativeToContext } from '../utils/path/relative-to-context';
77

8-
import type { Formatter } from './Formatter';
8+
import type { Formatter } from './formatter';
99

1010
function createWebpackFormatter(formatter: Formatter): Formatter {
1111
// mimics webpack error formatter
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
11
import type webpack from 'webpack';
22

3-
import type { ForkTsCheckerWebpackPluginConfiguration } from '../ForkTsCheckerWebpackPluginConfiguration';
4-
import type { ForkTsCheckerWebpackPluginState } from '../ForkTsCheckerWebpackPluginState';
53
import { getInfrastructureLogger } from '../infrastructure-logger';
4+
import type { ForkTsCheckerWebpackPluginConfig } from '../plugin-config';
5+
import type { ForkTsCheckerWebpackPluginState } from '../plugin-state';
66

7-
function interceptDoneToGetWebpackDevServerTap(
7+
function interceptDoneToGetDevServerTap(
88
compiler: webpack.Compiler,
9-
configuration: ForkTsCheckerWebpackPluginConfiguration,
9+
config: ForkTsCheckerWebpackPluginConfig,
1010
state: ForkTsCheckerWebpackPluginState
1111
) {
1212
const { debug } = getInfrastructureLogger(compiler);
1313

1414
// inspired by https://github.com/ypresto/fork-ts-checker-async-overlay-webpack-plugin
1515
compiler.hooks.done.intercept({
1616
register: (tap) => {
17-
if (
18-
tap.name === 'webpack-dev-server' &&
19-
tap.type === 'sync' &&
20-
configuration.logger.devServer
21-
) {
17+
if (tap.name === 'webpack-dev-server' && tap.type === 'sync' && config.logger.devServer) {
2218
debug('Intercepting webpack-dev-server tap.');
2319
state.webpackDevServerDoneTap = tap;
2420
}
@@ -27,4 +23,4 @@ function interceptDoneToGetWebpackDevServerTap(
2723
});
2824
}
2925

30-
export { interceptDoneToGetWebpackDevServerTap };
26+
export { interceptDoneToGetDevServerTap };

src/hooks/tapAfterCompileToAddDependencies.ts renamed to src/hooks/tap-after-compile-to-add-dependencies.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import type webpack from 'webpack';
22

3-
import type { ForkTsCheckerWebpackPluginConfiguration } from '../ForkTsCheckerWebpackPluginConfiguration';
4-
import type { ForkTsCheckerWebpackPluginState } from '../ForkTsCheckerWebpackPluginState';
53
import { getInfrastructureLogger } from '../infrastructure-logger';
4+
import type { ForkTsCheckerWebpackPluginConfig } from '../plugin-config';
5+
import type { ForkTsCheckerWebpackPluginState } from '../plugin-state';
66

77
function tapAfterCompileToAddDependencies(
88
compiler: webpack.Compiler,
9-
configuration: ForkTsCheckerWebpackPluginConfiguration,
9+
config: ForkTsCheckerWebpackPluginConfig,
1010
state: ForkTsCheckerWebpackPluginState
1111
) {
1212
const { debug } = getInfrastructureLogger(compiler);

src/hooks/tapAfterCompileToGetIssues.ts renamed to src/hooks/tap-after-compile-to-get-issues.ts

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
import type webpack from 'webpack';
22

3-
import type { ForkTsCheckerWebpackPluginConfiguration } from '../ForkTsCheckerWebpackPluginConfiguration';
4-
import type { ForkTsCheckerWebpackPluginState } from '../ForkTsCheckerWebpackPluginState';
53
import { getInfrastructureLogger } from '../infrastructure-logger';
64
import type { Issue } from '../issue';
7-
import { IssueWebpackError } from '../issue/IssueWebpackError';
8-
9-
import { getForkTsCheckerWebpackPluginHooks } from './pluginHooks';
5+
import { IssueWebpackError } from '../issue/issue-webpack-error';
6+
import type { ForkTsCheckerWebpackPluginConfig } from '../plugin-config';
7+
import { getPluginHooks } from '../plugin-hooks';
8+
import type { ForkTsCheckerWebpackPluginState } from '../plugin-state';
109

1110
function tapAfterCompileToGetIssues(
1211
compiler: webpack.Compiler,
13-
configuration: ForkTsCheckerWebpackPluginConfiguration,
12+
config: ForkTsCheckerWebpackPluginConfig,
1413
state: ForkTsCheckerWebpackPluginState
1514
) {
16-
const hooks = getForkTsCheckerWebpackPluginHooks(compiler);
15+
const hooks = getPluginHooks(compiler);
1716
const { debug } = getInfrastructureLogger(compiler);
1817

1918
compiler.hooks.afterCompile.tapPromise('ForkTsCheckerWebpackPlugin', async (compilation) => {
@@ -39,13 +38,13 @@ function tapAfterCompileToGetIssues(
3938
}
4039

4140
// filter list of issues by provided issue predicate
42-
issues = issues.filter(configuration.issue.predicate);
41+
issues = issues.filter(config.issue.predicate);
4342

4443
// modify list of issues in the plugin hooks
4544
issues = hooks.issues.call(issues, compilation);
4645

4746
issues.forEach((issue) => {
48-
const error = new IssueWebpackError(configuration.formatter(issue), issue);
47+
const error = new IssueWebpackError(config.formatter(issue), issue);
4948

5049
if (issue.severity === 'warning') {
5150
compilation.warnings.push(error);

src/hooks/tapAfterEnvironmentToPatchWatching.ts renamed to src/hooks/tap-after-environment-to-patch-watching.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import type webpack from 'webpack';
22

3-
import type { ForkTsCheckerWebpackPluginState } from '../ForkTsCheckerWebpackPluginState';
43
import { getInfrastructureLogger } from '../infrastructure-logger';
5-
import { InclusiveNodeWatchFileSystem } from '../watch/InclusiveNodeWatchFileSystem';
6-
import type { WatchFileSystem } from '../watch/WatchFileSystem';
4+
import type { ForkTsCheckerWebpackPluginState } from '../plugin-state';
5+
import { InclusiveNodeWatchFileSystem } from '../watch/inclusive-node-watch-file-system';
6+
import type { WatchFileSystem } from '../watch/watch-file-system';
77

88
function tapAfterEnvironmentToPatchWatching(
99
compiler: webpack.Compiler,

src/hooks/tapDoneToAsyncGetIssues.ts renamed to src/hooks/tap-done-to-async-get-issues.ts

+15-16
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
import chalk from 'chalk';
22
import type webpack from 'webpack';
33

4-
import type { ForkTsCheckerWebpackPluginConfiguration } from '../ForkTsCheckerWebpackPluginConfiguration';
5-
import type { ForkTsCheckerWebpackPluginState } from '../ForkTsCheckerWebpackPluginState';
6-
import { createWebpackFormatter } from '../formatter/WebpackFormatter';
4+
import { createWebpackFormatter } from '../formatter/webpack-formatter';
75
import { getInfrastructureLogger } from '../infrastructure-logger';
86
import type { Issue } from '../issue';
9-
import { IssueWebpackError } from '../issue/IssueWebpackError';
10-
import isPending from '../utils/async/isPending';
11-
import wait from '../utils/async/wait';
12-
13-
import { getForkTsCheckerWebpackPluginHooks } from './pluginHooks';
7+
import { IssueWebpackError } from '../issue/issue-webpack-error';
8+
import type { ForkTsCheckerWebpackPluginConfig } from '../plugin-config';
9+
import { getPluginHooks } from '../plugin-hooks';
10+
import type { ForkTsCheckerWebpackPluginState } from '../plugin-state';
11+
import { isPending } from '../utils/async/is-pending';
12+
import { wait } from '../utils/async/wait';
1413

1514
function tapDoneToAsyncGetIssues(
1615
compiler: webpack.Compiler,
17-
configuration: ForkTsCheckerWebpackPluginConfiguration,
16+
config: ForkTsCheckerWebpackPluginConfig,
1817
state: ForkTsCheckerWebpackPluginState
1918
) {
20-
const hooks = getForkTsCheckerWebpackPluginHooks(compiler);
19+
const hooks = getPluginHooks(compiler);
2120
const { log, debug } = getInfrastructureLogger(compiler);
2221

2322
compiler.hooks.done.tap('ForkTsCheckerWebpackPlugin', async (stats) => {
@@ -32,7 +31,7 @@ function tapDoneToAsyncGetIssues(
3231
try {
3332
if (await isPending(issuesPromise)) {
3433
hooks.waiting.call(stats.compilation);
35-
configuration.logger.issues.log(chalk.cyan('Issues checking in progress...'));
34+
config.logger.issues.log(chalk.cyan('Issues checking in progress...'));
3635
} else {
3736
// wait 10ms to log issues after webpack stats
3837
await wait(10);
@@ -51,25 +50,25 @@ function tapDoneToAsyncGetIssues(
5150
}
5251

5352
// filter list of issues by provided issue predicate
54-
issues = issues.filter(configuration.issue.predicate);
53+
issues = issues.filter(config.issue.predicate);
5554

5655
// modify list of issues in the plugin hooks
5756
issues = hooks.issues.call(issues, stats.compilation);
5857

59-
const formatter = createWebpackFormatter(configuration.formatter);
58+
const formatter = createWebpackFormatter(config.formatter);
6059

6160
if (issues.length) {
6261
// follow webpack's approach - one process.write to stderr with all errors and warnings
63-
configuration.logger.issues.error(issues.map((issue) => formatter(issue)).join('\n'));
62+
config.logger.issues.error(issues.map((issue) => formatter(issue)).join('\n'));
6463
} else {
65-
configuration.logger.issues.log(chalk.green('No issues found.'));
64+
config.logger.issues.log(chalk.green('No issues found.'));
6665
}
6766

6867
// report issues to webpack-dev-server, if it's listening
6968
// skip reporting if there are no issues, to avoid an extra hot reload
7069
if (issues.length && state.webpackDevServerDoneTap) {
7170
issues.forEach((issue) => {
72-
const error = new IssueWebpackError(configuration.formatter(issue), issue);
71+
const error = new IssueWebpackError(config.formatter(issue), issue);
7372

7473
if (issue.severity === 'warning') {
7574
stats.compilation.warnings.push(error);

0 commit comments

Comments
 (0)