Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: types #66

Merged
merged 5 commits into from
Feb 1, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion declarations/cjs.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
declare const _exports: typeof import('.').ESLintWebpackPlugin;
declare const _exports: typeof import('.').default;
export = _exports;
10 changes: 5 additions & 5 deletions declarations/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
export class ESLintWebpackPlugin {
export default ESLintWebpackPlugin;
export type Compiler = import('webpack').Compiler;
export type Options = import('./options').PluginOptions &
import('eslint').ESLint.Options;
declare class ESLintWebpackPlugin {
/**
* @param {Options} options
*/
Expand All @@ -20,7 +24,3 @@ export class ESLintWebpackPlugin {
*/
getContext(compiler: Compiler): string;
}
export default ESLintWebpackPlugin;
export type Compiler = import('webpack').Compiler;
export type Options = import('./options').PluginOptions &
import('eslint').ESLint.Options;
1 change: 1 addition & 0 deletions src/getESLint.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-ignore
import os from 'os';

import JestWorker from 'jest-worker';
Expand Down
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { isAbsolute, join } from 'path';

// @ts-ignore
import arrify from 'arrify';
// @ts-ignore
import micromatch from 'micromatch';
ricardogobbosouza marked this conversation as resolved.
Show resolved Hide resolved

import { getOptions } from './options';
Expand All @@ -12,7 +14,7 @@ import { parseFiles, parseFoldersToGlobs } from './utils';

const ESLINT_PLUGIN = 'ESLintWebpackPlugin';

export class ESLintWebpackPlugin {
class ESLintWebpackPlugin {
/**
* @param {Options} options
*/
Expand Down
4 changes: 2 additions & 2 deletions src/linter.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export default function linter(options, compilation) {
const { outputReport } = options;
// @ts-ignore
const save = (name, content) =>
new Promise((finish, bail) => {
/** @type {Promise<void>} */ (new Promise((finish, bail) => {
const { mkdir, writeFile } = compiler.outputFileSystem;
// ensure directory exists
// @ts-ignore - the types for `outputFileSystem` are missing the 3 arg overload
Expand All @@ -128,7 +128,7 @@ export default function linter(options, compilation) {
else finish();
});
});
});
}));

if (!outputReport || !outputReport.filePath) {
return;
Expand Down
1 change: 1 addition & 0 deletions src/options.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { validate } from 'schema-utils';

// @ts-ignore
import schema from './options.json';

/** @typedef {import("eslint").ESLint.Options} ESLintOptions */
Expand Down
9 changes: 5 additions & 4 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { statSync } from 'fs';

// @ts-ignore
import arrify from 'arrify';

const UNESCAPED_GLOB_SYMBOLS_RE = /(\\?)([()*?[\]{|}]|^!|[!+@](?=\())/g;
Expand All @@ -11,7 +12,7 @@ const UNESCAPED_GLOB_SYMBOLS_RE = /(\\?)([()*?[\]{|}]|^!|[!+@](?=\())/g;
*/
export function parseFiles(files, context) {
return arrify(files).map(
(file) =>
(/** @type {string} */ file) =>
`${replaceBackslashes(context).replace(
UNESCAPED_GLOB_SYMBOLS_RE,
'\\$2'
Expand All @@ -36,12 +37,12 @@ export function parseFoldersToGlobs(patterns, extensions = []) {
const extensionsList = arrify(extensions);
const [prefix, postfix] = extensionsList.length > 1 ? ['{', '}'] : ['', ''];
const extensionsGlob = extensionsList
.map((extension) => extension.replace(/^\./u, ''))
.map((/** @type {string} */ extension) => extension.replace(/^\./u, ''))
.join(',');

return arrify(patterns)
.map((pattern) => replaceBackslashes(pattern))
.map((pattern) => {
.map((/** @type {string} */ pattern) => replaceBackslashes(pattern))
.map((/** @type {string} */ pattern) => {
try {
// The patterns are absolute because they are prepended with the context.
const stats = statSync(pattern);
Expand Down
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"checkJs": true,
"strict": true,
"types": ["node"],
"esModuleInterop": true,
"resolveJsonModule": true
},
"include": ["./src/**/*"]
Expand Down