Skip to content

Commit

Permalink
chore: format using prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
Ffloriel committed Mar 29, 2024
1 parent 3eb1d36 commit 2e944d2
Show file tree
Hide file tree
Showing 32 changed files with 130 additions and 117 deletions.
2 changes: 1 addition & 1 deletion jest.config.ts
Expand Up @@ -21,7 +21,7 @@ const config: InitialOptionsTsJest = {

export function createConfig(
rootDir: string,
displayName: string
displayName: string,
): InitialOptionsTsJest {
return {
...config,
Expand Down
2 changes: 1 addition & 1 deletion packages/grunt-purgecss/src/index.ts
Expand Up @@ -2,7 +2,7 @@ import { PurgeCSS, defaultOptions, UserDefinedOptions } from "purgecss";

function getAvailableFiles(
grunt: IGrunt,
files: string[] | undefined = []
files: string[] | undefined = [],
): string[] {
return files.filter((filepath) => {
// Warn on and remove invalid source files (if nonull was set).
Expand Down
2 changes: 1 addition & 1 deletion packages/gulp-purgecss/__tests__/stream.test.ts
Expand Up @@ -41,7 +41,7 @@ describe("gulp-purgecss with stream", () => {
expect(data.includes("unused")).toBe(false);
expect(data.includes("a")).toBe(true);
done();
})
}),
);
});
});
Expand Down
4 changes: 2 additions & 2 deletions packages/postcss-purgecss/__tests__/index.test.ts
Expand Up @@ -30,7 +30,7 @@ describe("Purgecss postcss plugin", () => {

expect(result.css).toBe(output);
expect(result.warnings().length).toBe(0);
}
},
);

it.each(fileContents)(
Expand All @@ -53,7 +53,7 @@ describe("Purgecss postcss plugin", () => {
expect(result.warnings().length).toBe(0);
expect(contentFunction).toHaveBeenCalledTimes(1);
expect(contentFunction.mock.calls[0][0]).toContain(sourceFileName);
}
},
);

it(`queues messages when using reject flag: simple`, async () => {
Expand Down
16 changes: 8 additions & 8 deletions packages/postcss-purgecss/src/index.ts
Expand Up @@ -32,7 +32,7 @@ const PLUGIN_NAME = "postcss-purgecss";
async function purgeCSS(
opts: UserDefinedOptions,
root: postcss.Root,
{ result }: postcss.Helpers
{ result }: postcss.Helpers,
): Promise<void> {
const purgeCSS = new PurgeCSS();

Expand All @@ -49,13 +49,13 @@ async function purgeCSS(
...configFileOptions,
...opts,
safelist: standardizeSafelist(
opts?.safelist || configFileOptions?.safelist
opts?.safelist || configFileOptions?.safelist,
),
};

if (opts && typeof opts.contentFunction === "function") {
options.content = opts.contentFunction(
(root.source && root.source.input.file) || ""
(root.source && root.source.input.file) || "",
);
}

Expand All @@ -68,19 +68,19 @@ async function purgeCSS(
const { content, extractors } = options;

const fileFormatContents = content.filter(
(o) => typeof o === "string"
(o) => typeof o === "string",
) as string[];
const rawFormatContents = content.filter(
(o) => typeof o === "object"
(o) => typeof o === "object",
) as RawContent[];

const cssFileSelectors = await purgeCSS.extractSelectorsFromFiles(
fileFormatContents,
extractors
extractors,
);
const cssRawSelectors = await purgeCSS.extractSelectorsFromString(
rawFormatContents,
extractors
extractors,
);

const selectors = mergeExtractorSelectors(cssFileSelectors, cssRawSelectors);
Expand Down Expand Up @@ -114,7 +114,7 @@ async function purgeCSS(
* @public
*/
const purgeCSSPlugin: postcss.PluginCreator<UserDefinedOptions> = function (
opts
opts,
) {
if (typeof opts === "undefined")
throw new Error("PurgeCSS plugin does not have the correct options");
Expand Down
6 changes: 3 additions & 3 deletions packages/purgecss-from-html/__tests__/data.ts
Expand Up @@ -28,9 +28,9 @@ export const TEST_1_CLASS = ["test-container", "test-footer", "a-link"];
export const TEST_1_ID = ["a-link", "blo"];

export const TEST_1_ATTRIBUTES = {
NAMES: ["href", "id", "class", "type", "disabled"],
VALUES: ["#", "a-link", "a-link", "text", ...TEST_1_CLASS, ...TEST_1_ID]
}
NAMES: ["href", "id", "class", "type", "disabled"],
VALUES: ["#", "a-link", "a-link", "text", ...TEST_1_CLASS, ...TEST_1_ID],
};

export const TEST_2_CONTENT = `
<template>
Expand Down
10 changes: 8 additions & 2 deletions packages/purgecss-from-html/__tests__/index.test.ts
@@ -1,6 +1,12 @@
import purgehtml from "./../src/index";

import { TEST_1_CONTENT, TEST_1_TAG, TEST_1_CLASS, TEST_1_ID, TEST_1_ATTRIBUTES } from "./data";
import {
TEST_1_CONTENT,
TEST_1_TAG,
TEST_1_CLASS,
TEST_1_ID,
TEST_1_ATTRIBUTES,
} from "./data";
import { TEST_2_CONTENT, TEST_2_TAG, TEST_2_CLASS, TEST_2_ID } from "./data";

describe("purgehtml", () => {
Expand Down Expand Up @@ -67,7 +73,7 @@ describe("purgehtml", () => {
...resultTest2.classes,
...resultTest2.ids,
...resultTest2.tags,
].includes(item)
].includes(item),
).toBe(true);
}
});
Expand Down
6 changes: 3 additions & 3 deletions packages/purgecss-from-html/src/index.ts
Expand Up @@ -17,7 +17,7 @@ export type ExtractorResultDetailed = {

const mergedExtractorResults = (
resultLeft: ExtractorResultDetailed,
resultRight: ExtractorResultDetailed
resultRight: ExtractorResultDetailed,
): ExtractorResultDetailed => {
return {
attributes: {
Expand All @@ -35,7 +35,7 @@ const mergedExtractorResults = (
};

const getSelectorsInElement = (
element: htmlparser2.Htmlparser2TreeAdapterMap["element"]
element: htmlparser2.Htmlparser2TreeAdapterMap["element"],
): ExtractorResultDetailed => {
const result: ExtractorResultDetailed = {
attributes: {
Expand Down Expand Up @@ -65,7 +65,7 @@ const getSelectorsInElement = (
const getSelectorsInNodes = (
node:
| htmlparser2.Htmlparser2TreeAdapterMap["document"]
| htmlparser2.Htmlparser2TreeAdapterMap["element"]
| htmlparser2.Htmlparser2TreeAdapterMap["element"],
): ExtractorResultDetailed => {
let result: ExtractorResultDetailed = {
attributes: {
Expand Down
4 changes: 2 additions & 2 deletions packages/purgecss-from-jsx/src/index.ts
Expand Up @@ -32,7 +32,7 @@ function purgeFromJsx(options?: acorn.Options) {
// Parse and walk any JSXElement
walk.recursive<NodeState>(
acorn.Parser.extend(
jsx() as (BaseParser: typeof acorn.Parser) => typeof acorn.Parser
jsx() as (BaseParser: typeof acorn.Parser) => typeof acorn.Parser,
).parse(content, options || { ecmaVersion: "latest" }),
state,
{
Expand Down Expand Up @@ -94,7 +94,7 @@ function purgeFromJsx(options?: acorn.Options) {
}
},
},
{ ...walk.base }
{ ...walk.base },
);

return state.selectors || [];
Expand Down
2 changes: 1 addition & 1 deletion packages/purgecss-from-pug/src/index.ts
Expand Up @@ -25,7 +25,7 @@ const purgeFromPug = (content: string): string[] => {
...(token.mustEscape
? token.val.replace(/"/g, "")
: token.val
).split(" ")
).split(" "),
);
}
break;
Expand Down
2 changes: 1 addition & 1 deletion packages/purgecss-from-tsx/src/index.ts
Expand Up @@ -21,7 +21,7 @@ function purgeFromTsx(options?: {
jsx: ts.JsxEmit.Preserve,
...options?.tsOptions,
},
}).outputText
}).outputText,
);
};
}
Expand Down
2 changes: 1 addition & 1 deletion packages/purgecss-webpack-plugin/__tests__/index.test.ts
Expand Up @@ -8,7 +8,7 @@ const asyncFs = {
};

function runWebpack(
options: Configuration
options: Configuration,
): Promise<webpack.Stats | undefined> {
const compiler = webpack(options);
return new Promise((resolve, reject) => {
Expand Down
18 changes: 9 additions & 9 deletions packages/purgecss-webpack-plugin/src/index.ts
Expand Up @@ -42,7 +42,7 @@ function getPurgeCSSOptions(
filesToSearch: string[],
asset: sources.Source,
fileName: string,
sourceMap: boolean
sourceMap: boolean,
): PurgeCSSUserDefinedOptions {
const options = {
...defaultOptions,
Expand Down Expand Up @@ -92,7 +92,7 @@ function createSource(
name: string,
asset: sources.Source,
purgeResult: ResultPurge,
sourceMap: boolean
sourceMap: boolean,
): sources.Source {
if (!sourceMap || !purgeResult.sourceMap) {
return new sources.RawSource(purgeResult.css);
Expand All @@ -105,7 +105,7 @@ function createSource(
purgeResult.sourceMap,
source.toString(),
map,
false
false,
);
}

Expand All @@ -123,7 +123,7 @@ export class PurgeCSSPlugin {
apply(compiler: Compiler): void {
compiler.hooks.compilation.tap(
pluginName,
this.initializePlugin.bind(this)
this.initializePlugin.bind(this),
);
}

Expand Down Expand Up @@ -156,12 +156,12 @@ export class PurgeCSSPlugin {

async runPluginHook(
compilation: Compilation,
entryPaths: string[]
entryPaths: string[],
): Promise<void> {
const assetsFromCompilation = Object.entries(compilation.assets).filter(
([name]) => {
return isFileOfTypes(name, [".css"]);
}
},
);

for (const chunk of compilation.chunks) {
Expand All @@ -177,7 +177,7 @@ export class PurgeCSSPlugin {

for (const [name, asset] of assetsToPurge) {
const filesToSearch = entryPaths.filter(
(v) => !styleExtensions.some((ext) => v.endsWith(ext))
(v) => !styleExtensions.some((ext) => v.endsWith(ext)),
);

const sourceMapEnabled = !!compilation.compiler.options.devtool;
Expand All @@ -186,7 +186,7 @@ export class PurgeCSSPlugin {
filesToSearch,
asset,
name,
sourceMapEnabled
sourceMapEnabled,
);

const purgecss = await new PurgeCSS().purge(purgeCSSOptions);
Expand All @@ -198,7 +198,7 @@ export class PurgeCSSPlugin {

compilation.updateAsset(
name,
createSource(name, asset, purged, sourceMapEnabled)
createSource(name, asset, purged, sourceMapEnabled),
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/purgecss/__tests__/attributes.test.ts
Expand Up @@ -22,7 +22,7 @@ describe.each([
content: [`${ROOT_TEST_EXAMPLES}attributes/attribute_selector.html`],
css: [`${ROOT_TEST_EXAMPLES}attributes/attribute_selector.css`],
dynamicAttributes: ["aria-selected"],
extractors
extractors,
});
purgedCSS = resultsPurge[0].css;
});
Expand Down
2 changes: 1 addition & 1 deletion packages/purgecss/__tests__/cli/cli-console-output.test.ts
Expand Up @@ -19,7 +19,7 @@ describe("PurgeCSS CLI console output", () => {
]);
await run(program);
expect(console.log).toHaveBeenCalledWith(
`[{"css":".hello {\\n color: red;\\n}\\n","file":"${CLI_TEST_FOLDER}/src/style.css"}]`
`[{"css":".hello {\\n color: red;\\n}\\n","file":"${CLI_TEST_FOLDER}/src/style.css"}]`,
);
console.log = originalConsoleLog;
});
Expand Down
4 changes: 2 additions & 2 deletions packages/purgecss/__tests__/font-faces.test.ts
Expand Up @@ -13,12 +13,12 @@ describe("purge unused font-face", () => {
});
it("keep @font-face 'Cerebri Bold'", () => {
expect(
purgedCSS.includes(`src: url('../fonts/CerebriSans-Bold.eot?')`)
purgedCSS.includes(`src: url('../fonts/CerebriSans-Bold.eot?')`),
).toBe(true);
});
it("keep @font-face 'Cerebri Sans'", () => {
expect(
purgedCSS.includes(`src: url('../fonts/CerebriSans-Regular.eot?')`)
purgedCSS.includes(`src: url('../fonts/CerebriSans-Regular.eot?')`),
).toBe(true);
});
it("remove @font-face 'OtherFont'", () => {
Expand Down
20 changes: 10 additions & 10 deletions packages/purgecss/__tests__/index.test.ts
Expand Up @@ -13,7 +13,7 @@ describe("purgecss with config file", () => {
it("throws an error if config file is not found", async () => {
expect.assertions(1);
await expect(
new PurgeCSS().purge("./__tests__/purgecss_wrong_path.config.js")
new PurgeCSS().purge("./__tests__/purgecss_wrong_path.config.js"),
).rejects.toThrow();
});
});
Expand Down Expand Up @@ -98,20 +98,21 @@ describe("Warn if no files are found from the option 'content'", () => {
console.warn = jest.fn();
await new PurgeCSS().purge({
content: ["./__tests__/not-found.js", "./__tests__/not-found.html"],
css: [`${ROOT_TEST_EXAMPLES}others/remove_unused.css`]
css: [`${ROOT_TEST_EXAMPLES}others/remove_unused.css`],
});
expect(console.warn).toHaveBeenCalledTimes(1);
expect(console.warn).toHaveBeenCalledWith(
"No files found from the passed PurgeCSS option 'content'.");
console.warn = originalConsoleWarn;
})
"No files found from the passed PurgeCSS option 'content'.",
);
console.warn = originalConsoleWarn;
});

it("does not warn if files are found", async () => {
const originalConsoleWarn = console.warn;
console.warn = jest.fn();
await new PurgeCSS().purge({
content: [`${ROOT_TEST_EXAMPLES}others/remove_unused.js`],
css: [`${ROOT_TEST_EXAMPLES}others/remove_unused.css`]
css: [`${ROOT_TEST_EXAMPLES}others/remove_unused.css`],
});
expect(console.warn).not.toHaveBeenCalled();
console.warn = originalConsoleWarn;
Expand All @@ -121,11 +122,10 @@ describe("Warn if no files are found from the option 'content'", () => {
const originalConsoleWarn = console.warn;
console.warn = jest.fn();
await new PurgeCSS().purge({
content: [{ raw: '<div class="a">test</div>', extension: 'html' }],
css: [`${ROOT_TEST_EXAMPLES}others/remove_unused.css`]
content: [{ raw: '<div class="a">test</div>', extension: "html" }],
css: [`${ROOT_TEST_EXAMPLES}others/remove_unused.css`],
});
expect(console.warn).not.toHaveBeenCalled();
console.warn = originalConsoleWarn;
});

})
});
2 changes: 1 addition & 1 deletion packages/purgecss/__tests__/performance.test.ts
Expand Up @@ -16,7 +16,7 @@ describe("performance", () => {
expect(
results.some((result) => {
return result.file && result.file.endsWith("/tailwind.css");
})
}),
).toBe(true);
results.forEach((result) => expect(typeof result.css).toBe("string"));
console.log("performance test took", Date.now() - start, "ms");
Expand Down

0 comments on commit 2e944d2

Please sign in to comment.