Skip to content

Commit

Permalink
fix: eslint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
gjbkz committed Aug 19, 2022
1 parent 62ea1f1 commit 3a339f8
Show file tree
Hide file tree
Showing 33 changed files with 82 additions and 63 deletions.
1 change: 1 addition & 0 deletions @types/css.d.ts
@@ -1,3 +1,4 @@
// eslint-disable-next-line import/unambiguous
declare module '*.css' {
export const className: Record<string, string>;
export const id: Record<string, string>;
Expand Down
2 changes: 2 additions & 0 deletions @types/postcss-scss/index.d.ts
@@ -1,5 +1,7 @@
// eslint-disable-next-line import/unambiguous
declare module 'postcss-scss' {
import type {Parser, Stringifier} from 'postcss';

export const parse: Parser;
export const stringify: Stringifier;
}
4 changes: 3 additions & 1 deletion package.json
Expand Up @@ -95,7 +95,9 @@
"*.css.ts"
],
"rules": {
"@nlib/no-globals": "off"
"no-lone-blocks": "off",
"@nlib/no-globals": "off",
"import/no-relative-parent-imports": "off"
},
"overrides": [
{
Expand Down
2 changes: 2 additions & 0 deletions scripts/chmodScripts.ts
@@ -1,5 +1,7 @@
/* eslint-disable import/no-import-module-exports */
import * as path from 'path';
import * as fs from 'fs';

const afs = fs.promises;

export const permitExecution = async (
Expand Down
13 changes: 7 additions & 6 deletions scripts/copy.ts
@@ -1,4 +1,5 @@
import {promises as afs} from 'fs';
/* eslint-disable import/no-import-module-exports */
import * as fs from 'fs/promises';
import * as path from 'path';

/**
Expand All @@ -11,16 +12,16 @@ export const copy = async (
): Promise<void> => {
src = path.normalize(src);
dest = path.normalize(dest);
if ((await afs.stat(src)).isDirectory()) {
await afs.mkdir(dest, {recursive: true});
await Promise.all((await afs.readdir(src)).map(async (name) => {
if ((await fs.stat(src)).isDirectory()) {
await fs.mkdir(dest, {recursive: true});
await Promise.all((await fs.readdir(src)).map(async (name) => {
const srcFile = path.join(src, name);
const destFile = path.join(dest, name);
await afs.copyFile(srcFile, destFile);
await fs.copyFile(srcFile, destFile);
console.log(`Copied: ${srcFile}${destFile}`);
}));
} else {
await afs.copyFile(src, dest);
await fs.copyFile(src, dest);
console.log(`Copied: ${src}${dest}`);
}
};
Expand Down
1 change: 1 addition & 0 deletions src/bin/loadParameters.ts
@@ -1,6 +1,7 @@
import * as path from 'path';
import * as fs from 'fs';
import type {SessionOptions} from '../runner/types.js';

const {readFile} = fs.promises;

interface EsifyCSSCommandOptions {
Expand Down
2 changes: 1 addition & 1 deletion src/minifier/minifyCSSInScript.ts
@@ -1,6 +1,6 @@
import type {CSSRange} from './types';
import type {IdGenerator} from '../util/createIdGenerator';
import {encodeString} from '../util/encodeString';
import type {CSSRange} from './types';

export const minifyCSSInScript = (
script: string,
Expand Down
3 changes: 2 additions & 1 deletion src/minifier/minifyScripts.ts
@@ -1,9 +1,10 @@
import * as fs from 'fs';
import {updateFile} from '../util/updateFile';
import {createOptimizedIdGenerator} from './createOptimizedIdGenerator';
import {parseScripts} from './parseScripts';
import {minifyCSSInScript} from './minifyCSSInScript';
import {setDictionary} from './setDictionary';
import {updateFile} from '../util/updateFile';

const {readFile} = fs.promises;

export const minifyScripts = async (
Expand Down
2 changes: 1 addition & 1 deletion src/minifier/parseCSSModuleScript.test.ts
Expand Up @@ -242,7 +242,7 @@ interface Test {
t.deepEqual(actual, expected);
} else {
const error = t.throws(() => parseCSSModuleScript(input));
t.is(error.message.slice(0, input.title.length), input.title);
t.is(error && error.message.slice(0, input.title.length), input.title);
}
});
});
2 changes: 1 addition & 1 deletion src/minifier/parseScripts.ts
@@ -1,7 +1,7 @@
import * as fs from 'fs';
import {tokenizeString} from '../util/tokenizeString';
import type {ParseScriptsResult, ScriptData} from './types';
import {parseCSSModuleScript} from './parseCSSModuleScript';
import {tokenizeString} from '../util/tokenizeString';

const cache = new Map<string, {
mtimeMs: number,
Expand Down
2 changes: 1 addition & 1 deletion src/postcssPlugin/createTransformer.ts
@@ -1,12 +1,12 @@
import type * as postcss from 'postcss';
import {normalizePath} from '../util/normalizePath';
import type {PluginConfiguration, EsifyCSSResult} from './types';
import {transformDeclarations} from './transformDeclarations';
import {getImports} from './getImports';
import {minify} from './minify';
import {mangleIdentifiers} from './mangleIdentifiers';
import {mangleKeyFrames} from './mangleKeyFrames';
import {removeImportsAndRaws} from './removeImportsAndRaws';
import {normalizePath} from '../util/normalizePath';

export const createTransformer = (
{mangler, rawPrefix}: PluginConfiguration,
Expand Down
2 changes: 1 addition & 1 deletion src/postcssPlugin/getDependencies.ts
@@ -1,5 +1,5 @@
import type * as postcss from 'postcss';
import * as path from 'path';
import type * as postcss from 'postcss';

export const REGEX_IMPORT = /^(['"])([^\s'"]+)\1\s*([^\s]*)$/;

Expand Down
2 changes: 1 addition & 1 deletion src/postcssPlugin/getMatchedImport.ts
@@ -1,5 +1,5 @@
import type {Imports} from './types';
import {normalizePath} from '../util/normalizePath';
import type {Imports} from './types';

export const getMatchedImport = (
value: string,
Expand Down
2 changes: 1 addition & 1 deletion src/postcssPlugin/getPluginConfiguration.ts
@@ -1,9 +1,9 @@
import {createIdentifier} from '../util/createIdGenerator';
import type {
PluginOptions,
PluginConfiguration,
PluginMangler,
} from './types';
import {createIdentifier} from '../util/createIdGenerator';

export const getPluginMangler = (
{
Expand Down
16 changes: 8 additions & 8 deletions src/postcssPlugin/plugin.test.ts
@@ -1,9 +1,9 @@
import * as parser from '@hookun/parse-animation-shorthand';
import test from 'ava';
import type {Rule, Declaration, AtRule} from 'postcss';
import type {AtRule, Declaration, Rule} from 'postcss';
import {extractPluginResult} from '../runner/extractPluginResult';
import {postcss} from '../util/postcss';
import * as parser from '@hookun/parse-animation-shorthand';
import {plugin} from './plugin';
import {extractPluginResult} from '../runner/extractPluginResult';

const getFirstDeclaration = (
rule: Rule,
Expand Down Expand Up @@ -56,7 +56,7 @@ test('plugin', async (t): Promise<void> => {
const node = nodes[index++] as AtRule;
t.is(node.type, 'atrule');
t.is(node.name, 'keyframes');
t.is(node.params, mapA.keyframes.aaa);
t.is(node.params, `${mapA.keyframes.aaa}`);
}
{
const node = nodes[index++] as Rule;
Expand All @@ -65,7 +65,7 @@ test('plugin', async (t): Promise<void> => {
{
const declaration = getFirstDeclaration(node);
t.is(declaration.prop, 'animation-name');
t.is(declaration.value, mapA.keyframes.aaa);
t.is(declaration.value, `${mapA.keyframes.aaa}`);
}
}
{
Expand All @@ -88,7 +88,7 @@ test('plugin', async (t): Promise<void> => {
{
const declaration = getFirstDeclaration(node);
t.is(declaration.prop, 'animation-name');
t.is(declaration.value, mapB.keyframes.aaa);
t.is(declaration.value, `${mapB.keyframes.aaa}`);
}
}
{
Expand All @@ -105,7 +105,7 @@ test('plugin', async (t): Promise<void> => {
const node = nodes[index++] as AtRule;
t.is(node.type, 'atrule');
t.is(node.name, 'keyframes');
t.is(node.params, mapB.keyframes.aaa);
t.is(node.params, `${mapB.keyframes.aaa}`);
}
{
const node = nodes[index++] as Rule;
Expand All @@ -114,7 +114,7 @@ test('plugin', async (t): Promise<void> => {
{
const declaration = getFirstDeclaration(node);
t.is(declaration.prop, 'animation-name');
t.is(declaration.value, mapA.keyframes.aaa);
t.is(declaration.value, `${mapA.keyframes.aaa}`);
}
}
{
Expand Down
2 changes: 1 addition & 1 deletion src/postcssPlugin/transformDeclarations.ts
@@ -1,5 +1,5 @@
import type * as postcss from 'postcss';
import * as console from 'console';
import type * as postcss from 'postcss';
import * as animationParser from '@hookun/parse-animation-shorthand';
import type {EsifyCSSResult, Imports, PluginMangler} from './types';
import {getMatchedImport} from './getMatchedImport';
Expand Down
28 changes: 14 additions & 14 deletions src/runner/Session.test.ts
@@ -1,26 +1,26 @@
import * as path from 'path';
import * as events from 'events';
import * as fs from 'fs';
import * as path from 'path';
import * as stream from 'stream';
import * as events from 'events';
import type {TestInterface, ExecutionContext} from 'ava';
import * as animationParser from '@hookun/parse-animation-shorthand';
import type {ExecutionContext, TestFn} from 'ava';
import anyTest from 'ava';
import * as postcss from 'postcss';
import * as scss from 'postcss-scss';
import * as animationParser from '@hookun/parse-animation-shorthand';
import type {SessionOptions} from './types';
import {Session} from './Session';
import {deleteFile} from '..';
import {createTemporaryDirectory} from '../util/createTemporaryDirectory';
import type {RunCodeResult} from '../util/runCode.for-test';
import {runCode} from '../util/runCode.for-test';
import {updateFile} from '../util/updateFile';
import {deleteFile} from '..';
import {Session} from './Session';
import type {SessionOptions} from './types';

interface TestContext {
directory: string,
session?: Session,
}

const test = anyTest as TestInterface<TestContext>;
const test = anyTest as TestFn<TestContext>;
const isRule = (input: postcss.ChildNode): input is postcss.Rule => input.type === 'rule';
const createMessageListener = () => {
const messageListener = new events.EventEmitter();
Expand Down Expand Up @@ -76,13 +76,13 @@ interface Test {
t.deepEqual(Object.keys(className), ['foo']);
t.deepEqual(Object.keys(keyframes), []);
const [ruleNode, anotherNode] = root.nodes as Array<postcss.Rule>;
t.is(anotherNode, undefined);
t.falsy(anotherNode);
t.like(ruleNode, {
type: 'rule',
selector: `.${className.foo}`,
});
const [declaration, anotherDeclaration] = ruleNode.nodes;
t.is(anotherDeclaration, undefined);
t.falsy(anotherDeclaration);
t.like(declaration, {
type: 'decl',
prop: 'color',
Expand All @@ -106,13 +106,13 @@ interface Test {
t.deepEqual(Object.keys(className), ['foo']);
t.deepEqual(Object.keys(keyframes), []);
const [ruleNode, anotherNode] = root.nodes as Array<postcss.Rule>;
t.is(anotherNode, undefined);
t.falsy(anotherNode);
t.like(ruleNode, {
type: 'rule',
selector: `.${className.foo}`,
});
const [declaration, anotherDeclaration] = ruleNode.nodes;
t.is(anotherDeclaration, undefined);
t.falsy(anotherDeclaration);
t.like(declaration, {
type: 'decl',
prop: 'color',
Expand Down Expand Up @@ -347,8 +347,8 @@ test('watch', async (t) => {
const atRule2 = nodes2[0] as postcss.AtRule;
t.is(atRule1.name, 'keyframes');
t.is(atRule2.name, 'keyframes');
t.is(atRule1.params, result1.keyframes.foo);
t.is(atRule1.params, result1.keyframes.foo);
t.is(atRule1.params, `${result1.keyframes.foo}`);
t.is(atRule1.params, `${result1.keyframes.foo}`);
}
{
const rule1 = nodes1[1] as postcss.Rule;
Expand Down
15 changes: 8 additions & 7 deletions src/runner/Session.ts
@@ -1,19 +1,20 @@
import * as fs from 'fs';
import * as chokidar from 'chokidar';
import * as path from 'path';
import type {SessionOptions, SessionConfiguration} from './types';
import {getSessionConfiguration} from './getSessionConfiguration';
import {parseCSS} from './parseCSS';
import {extractPluginResult} from './extractPluginResult';
import {generateScript} from './generateScript';
import {waitForInitialScanCompletion} from './waitForInitialScanCompletion';
import * as chokidar from 'chokidar';
import {minifyScripts} from '../minifier/minifyScripts';
import type {ExposedPromise} from '../util/createExposedPromise';
import {createExposedPromise} from '../util/createExposedPromise';
import {minifyScriptsForCSS} from '../minifier/minifyScriptsForCSS';
import {deleteFile} from '../util/deleteFile';
import {updateFile} from '../util/updateFile';
import {serialize} from '../util/serialize';
import {waitForInitialScanCompletion} from './waitForInitialScanCompletion';
import {generateScript} from './generateScript';
import {extractPluginResult} from './extractPluginResult';
import {parseCSS} from './parseCSS';
import {getSessionConfiguration} from './getSessionConfiguration';
import type {SessionOptions, SessionConfiguration} from './types';

const {copyFile} = fs.promises;

export class Session {
Expand Down
1 change: 1 addition & 0 deletions src/runner/getCSSParserConfiguration.ts
@@ -1,5 +1,6 @@
import * as fs from 'fs';
import type {CSSParserParameters, CSSParserConfigurations} from './types';

const {readFile} = fs.promises;

export const getCSSParserConfiguration = async (
Expand Down
2 changes: 1 addition & 1 deletion src/runner/getChokidarOptions.ts
@@ -1,6 +1,6 @@
import type {WatchOptions} from 'chokidar';
import type {SessionOptions, ReadonlyWatchOptions} from './types';
import {ensureArray} from '../util/ensureArray';
import type {SessionOptions, ReadonlyWatchOptions} from './types';

export const getChokidarOptions = (
{chokidar: chokidarOptions = {}, exclude, css}: SessionOptions,
Expand Down
2 changes: 1 addition & 1 deletion src/runner/getOutputOption.ts
@@ -1,5 +1,5 @@
import type {SessionConfiguration, SessionOutput} from './types';
import {getBase64UrlHash} from '../util/getBase64UrlHash';
import type {SessionConfiguration, SessionOutput} from './types';

export const getOutputOption = (
{helper, css}: {helper?: string, css?: string},
Expand Down
2 changes: 1 addition & 1 deletion src/runner/getSessionConfiguration.ts
@@ -1,6 +1,6 @@
import type {SessionConfiguration, SessionOptions} from './types';
import {plugin} from '../postcssPlugin/plugin';
import {ensureArray} from '../util/ensureArray';
import type {SessionConfiguration, SessionOptions} from './types';
import {getChokidarOptions} from './getChokidarOptions';
import {getOutputOption} from './getOutputOption';
import {getExtensionOption} from './getExtensionOption';
Expand Down
2 changes: 1 addition & 1 deletion src/runner/types.ts
@@ -1,6 +1,6 @@
import type {Writable} from 'stream';
import type {Matcher} from 'anymatch';
import type {AwaitWriteFinishOptions, WatchOptions} from 'chokidar';
import type {Writable} from 'stream';
import type {AcceptedPlugin, ProcessOptions, SourceMapOptions} from 'postcss';
import type {PluginOptions} from '../postcssPlugin/types';

Expand Down
2 changes: 1 addition & 1 deletion src/util/createExposedPromise.test.ts
Expand Up @@ -13,5 +13,5 @@ test('#1 reject', async (t) => {
const message = 'Expected';
exposed.reject(new Error(message));
const error = await t.throwsAsync(exposed.promise);
t.is(error.message, message);
t.is(error && error.message, message);
});
1 change: 1 addition & 0 deletions src/util/createTemporaryDirectory.ts
@@ -1,6 +1,7 @@
import * as path from 'path';
import * as os from 'os';
import * as fs from 'fs';

const {mkdtemp} = fs.promises;

export const createTemporaryDirectory = async (
Expand Down
1 change: 1 addition & 0 deletions src/util/deleteFile.test.ts
Expand Up @@ -4,6 +4,7 @@ import ava from 'ava';
import {createTemporaryDirectory} from './createTemporaryDirectory';
import {deleteFile} from './deleteFile';
import {updateFile} from './updateFile';

const {stat, mkdir} = fs.promises;

ava('delete a file', async (t) => {
Expand Down
1 change: 1 addition & 0 deletions src/util/deleteFile.ts
@@ -1,5 +1,6 @@
import * as path from 'path';
import * as fs from 'fs';

const {unlink, readdir, rmdir} = fs.promises;

export const deleteFile = async (
Expand Down
2 changes: 1 addition & 1 deletion src/util/encodeString.ts
@@ -1,6 +1,6 @@
import * as vlq from 'vlq';
import type {IdGenerator} from './createIdGenerator';
import {tokenizeString} from './tokenizeString';
import * as vlq from 'vlq';

export const encodeString = (
string: string,
Expand Down
1 change: 1 addition & 0 deletions src/util/postcss.d.ts
@@ -1,2 +1,3 @@
import postcss from 'postcss';

export {postcss};

0 comments on commit 3a339f8

Please sign in to comment.