Skip to content

Commit

Permalink
chore(prettier): upgrade to latest and sort imports
Browse files Browse the repository at this point in the history
  • Loading branch information
skovy committed Aug 7, 2023
1 parent 618355f commit 052e055
Show file tree
Hide file tree
Showing 33 changed files with 86 additions and 74 deletions.
3 changes: 3 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"plugins": ["prettier-plugin-organize-imports"]
}
1 change: 0 additions & 1 deletion __tests__/core/generate.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import fs from "fs";

import { generate } from "../../lib/core";
import { describeAllImplementations } from "../helpers";

Expand Down
1 change: 0 additions & 1 deletion __tests__/core/list-different.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { listDifferent } from "../../lib/core";

import { describeAllImplementations } from "../helpers";

describeAllImplementations((implementation) => {
Expand Down
3 changes: 1 addition & 2 deletions __tests__/core/remove-file.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import fs from "fs";
import path from "path";

import { DEFAULT_OPTIONS } from "../../lib/load";
import { alerts } from "../../lib/core/alerts";
import { removeSCSSTypeDefinitionFile } from "../../lib/core/remove-file";
import { DEFAULT_OPTIONS } from "../../lib/load";

describe("removeFile", () => {
const originalTestFile = path.resolve(__dirname, "..", "removable.scss");
Expand Down
4 changes: 1 addition & 3 deletions __tests__/core/write-file.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import fs from "fs";
import path from "path";

import { writeFile } from "../../lib/core";

import { describeAllImplementations } from "../helpers";

describeAllImplementations((implementation) => {
Expand Down Expand Up @@ -197,7 +195,7 @@ describeAllImplementations((implementation) => {
outputFolder: null,
});

expect(fs.statSync).not.toBeCalled();
expect(fs.statSync).not.toHaveBeenCalledWith(testFile);
});
});
});
Expand Down
1 change: 0 additions & 1 deletion __tests__/dart-sass/dart-sass.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import fs from "fs";
import slash from "slash";

import { alerts } from "../../lib/core";
import { main } from "../../lib/main";

Expand Down
3 changes: 1 addition & 2 deletions __tests__/implementations/get-implementation.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import sass from "sass";
import nodeSass from "node-sass";

import sass from "sass";
import { getImplementation } from "../../lib/implementations";

describe("getImplementation", () => {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/load.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from "path";
import { loadConfig, mergeOptions, DEFAULT_OPTIONS } from "../lib/load";
import { DEFAULT_OPTIONS, loadConfig, mergeOptions } from "../lib/load";

const CONFIG_CASES = [
"js-default-export",
Expand Down
1 change: 0 additions & 1 deletion __tests__/main.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import fs from "fs";
import path from "path";
import slash from "slash";

import { alerts } from "../lib/core";
import { main } from "../lib/main";
import { describeAllImplementations } from "./helpers";
Expand Down
3 changes: 1 addition & 2 deletions __tests__/prettier/prettier.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import prettier from "prettier";
import { attemptPrettier } from "../../lib/prettier";
import { classNamesToTypeDefinitions } from "../../lib/typescript";

import prettier from "prettier";

const input =
"export type Styles = {'myClass': string;'yourClass': string;}; export type Classes = keyof Styles; declare const styles: Styles; export default styles;";

Expand Down
1 change: 0 additions & 1 deletion __tests__/sass/file-to-class-names.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { fileToClassNames } from "../../lib/sass";

import { describeAllImplementations } from "../helpers";

describeAllImplementations((implementation) => {
Expand Down
1 change: 0 additions & 1 deletion __tests__/typescript/get-type-definition-path.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import path from "path";

import { DEFAULT_OPTIONS } from "../../lib/load";
import { getTypeDefinitionPath } from "../../lib/typescript";

Expand Down
2 changes: 1 addition & 1 deletion examples/default-export/feature-a/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import styles, { Styles, ClassNames } from "./style.scss";
import styles, { ClassNames, Styles } from "./style.scss";

console.log(styles.i);
console.log(styles["i-am-kebab-cased"]);
Expand Down
7 changes: 3 additions & 4 deletions lib/cli.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#!/usr/bin/env node

import yargs from "yargs";

import { Aliases, NAME_FORMATS } from "./sass";
import { EXPORT_TYPES, QUOTE_TYPES, LOG_LEVELS } from "./typescript";
import { main } from "./main";
import { IMPLEMENTATIONS } from "./implementations";
import { main } from "./main";
import { Aliases, NAME_FORMATS } from "./sass";
import { EXPORT_TYPES, LOG_LEVELS, QUOTE_TYPES } from "./typescript";

const { _: patterns, ...rest } = yargs
.usage(
Expand Down
2 changes: 1 addition & 1 deletion lib/core/alerts.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import chalk from "chalk";

export const LOG_LEVELS = ["verbose", "error", "info", "silent"] as const;
export type LogLevel = typeof LOG_LEVELS[number];
export type LogLevel = (typeof LOG_LEVELS)[number];

export const logLevelDefault: LogLevel = "verbose";

Expand Down
5 changes: 2 additions & 3 deletions lib/core/list-different.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import fs from "fs";

import { alerts } from "./alerts";
import { ConfigOptions } from "./types";
import { fileToClassNames } from "../sass";
import {
classNamesToTypeDefinitions,
getTypeDefinitionPath,
} from "../typescript";
import { alerts } from "./alerts";
import { listFilesAndPerformSanityChecks } from "./list-files-and-perform-sanity-checks";
import { ConfigOptions } from "./types";

export const listDifferent = async (
pattern: string,
Expand Down
1 change: 0 additions & 1 deletion lib/core/list-files-and-perform-sanity-checks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import glob from "glob";

import { alerts } from "./alerts";
import { ConfigOptions } from "./types";

Expand Down
5 changes: 2 additions & 3 deletions lib/core/remove-file.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import fs from "fs";

import { alerts } from "./alerts";
import { getTypeDefinitionPath } from "../typescript";
import { ConfigOptions } from ".";
import { getTypeDefinitionPath } from "../typescript";
import { alerts } from "./alerts";

/**
* Given a single file remove the file
Expand Down
2 changes: 1 addition & 1 deletion lib/core/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SASSOptions } from "../sass";
import { ExportType, QuoteType, LogLevel } from "../typescript";
import { ExportType, LogLevel, QuoteType } from "../typescript";

type CLIOnlyOptions = Extract<keyof SASSOptions, "importer">;

Expand Down
5 changes: 2 additions & 3 deletions lib/core/watch.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import chokidar from "chokidar";

import { alerts } from "./alerts";
import { listFilesAndPerformSanityChecks } from "./list-files-and-perform-sanity-checks";
import { removeSCSSTypeDefinitionFile } from "./remove-file";
import { writeFile } from "./write-file";
import { ConfigOptions } from "./types";
import { listFilesAndPerformSanityChecks } from "./list-files-and-perform-sanity-checks";
import { writeFile } from "./write-file";

/**
* Watch a file glob and generate the corresponding types.
Expand Down
9 changes: 4 additions & 5 deletions lib/core/write-file.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import fs from "fs";
import path from "path";
import { SassError } from "node-sass";

import { alerts } from "./alerts";
import path from "path";
import { fileToClassNames } from "../sass";
import {
getTypeDefinitionPath,
classNamesToTypeDefinitions,
getTypeDefinitionPath,
} from "../typescript";
import { fileToClassNames } from "../sass";
import { alerts } from "./alerts";
import { CLIOptions } from "./types";

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/implementations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import sass from "sass";
* all of the same logic can be reused.
*/
export const IMPLEMENTATIONS = ["node-sass", "sass"] as const;
export type Implementations = typeof IMPLEMENTATIONS[number];
export type Implementations = (typeof IMPLEMENTATIONS)[number];

type Implementation = typeof nodeSass | typeof sass;

Expand Down
9 changes: 4 additions & 5 deletions lib/load.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import path from "path";
import JoyCon from "joycon";
import { bundleRequire } from "bundle-require";

import JoyCon from "joycon";
import path from "path";
import { alerts, CLIOptions, ConfigOptions } from "./core";
import { getDefaultImplementation } from "./implementations";
import { nameFormatDefault } from "./sass";
import {
bannerTypeDefault,
exportTypeDefault,
exportTypeInterfaceDefault,
exportTypeNameDefault,
quoteTypeDefault,
logLevelDefault,
quoteTypeDefault,
} from "./typescript";
import { getDefaultImplementation } from "./implementations";

const VALID_CONFIG_FILES = [
"typed-scss-modules.config.ts",
Expand Down
5 changes: 2 additions & 3 deletions lib/main.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import fs from "fs";
import path from "path";
import slash from "slash";
import { loadConfig, mergeOptions } from "./load";

import {
watch,
CLIOptions,
generate,
listDifferent,
setAlertsLogLevel,
watch,
} from "./core";
import { loadConfig, mergeOptions } from "./load";

export const main = async (
pattern: string,
Expand Down
3 changes: 1 addition & 2 deletions lib/prettier/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { format, resolveConfig } from "prettier";
import { alerts } from "../core";
import { canResolvePrettier } from "./can-resolve";

import { format, resolveConfig } from "prettier";

interface Prettier {
format: typeof format;
resolveConfig: typeof resolveConfig;
Expand Down
9 changes: 4 additions & 5 deletions lib/sass/file-to-class-names.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import fs from "fs";
import {
camelCase,
camelCaseTransformMerge,
paramCase,
snakeCase,
} from "change-case";

import fs from "fs";
import { getImplementation, Implementations } from "../implementations";
import { Aliases, customImporters, SASSImporterOptions } from "./importer";
import { sourceToClassNames } from "./source-to-class-names";
import { Implementations, getImplementation } from "../implementations";
import { customImporters, Aliases, SASSImporterOptions } from "./importer";

export { Aliases };
export type ClassName = string;
Expand All @@ -33,7 +32,7 @@ const NAME_FORMATS_WITH_TRANSFORMER = Object.keys(
) as NameFormatWithTransformer[];

export const NAME_FORMATS = [...NAME_FORMATS_WITH_TRANSFORMER, "all"] as const;
export type NameFormat = typeof NAME_FORMATS[number];
export type NameFormat = (typeof NAME_FORMATS)[number];

export interface SASSOptions extends SASSImporterOptions {
additionalData?: string;
Expand Down
2 changes: 1 addition & 1 deletion lib/sass/importer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { LegacySyncImporter } from "sass";
import { SyncImporter } from "node-sass";
import { LegacySyncImporter } from "sass";

// Hacky way to merge both dart-sass and node-sass importer definitions.
type Importer = LegacySyncImporter & SyncImporter;
Expand Down
6 changes: 3 additions & 3 deletions lib/sass/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export {
nameFormatDefault,
fileToClassNames,
Aliases,
SASSOptions,
fileToClassNames,
nameFormatDefault,
NAME_FORMATS,
SASSOptions,
} from "./file-to-class-names";
4 changes: 1 addition & 3 deletions lib/typescript/class-names-to-type-definition.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { ClassName } from "lib/sass/file-to-class-names";
import os from "os";

import reserved from "reserved-words";

import { ClassName } from "lib/sass/file-to-class-names";
import { alerts } from "../core";
import { attemptPrettier } from "../prettier";

Expand Down
3 changes: 1 addition & 2 deletions lib/typescript/get-type-definition-path.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ConfigOptions } from "../core";

import path from "path";
import { ConfigOptions } from "../core";

const CURRENT_WORKING_DIRECTORY = process.cwd();

Expand Down
8 changes: 4 additions & 4 deletions lib/typescript/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
export { LogLevel, logLevelDefault, LOG_LEVELS } from "../core/alerts";
export {
bannerTypeDefault,
classNamesToTypeDefinitions,
ExportType,
exportTypeDefault,
exportTypeInterfaceDefault,
exportTypeNameDefault,
quoteTypeDefault,
ExportType,
QuoteType,
EXPORT_TYPES,
QuoteType,
quoteTypeDefault,
QUOTE_TYPES,
} from "./class-names-to-type-definition";
export { logLevelDefault, LogLevel, LOG_LEVELS } from "../core/alerts";
export { getTypeDefinitionPath } from "./get-type-definition-path";
Loading

0 comments on commit 052e055

Please sign in to comment.