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: extract constants and types #399

Merged
merged 2 commits into from
Jun 23, 2022
Merged
Show file tree
Hide file tree
Changes from all 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 src/options/attribute-sorting/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ChoiceSupportOption, PathArraySupportOption } from 'prettier';
import { CATEGORY_PUG } from '..';
import { CATEGORY_PUG } from '../constants';

const pugSortAttributesOption: PathArraySupportOption = {
since: '1.7.0',
Expand Down
2 changes: 1 addition & 1 deletion src/options/common.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ChoiceSupportOption, IntSupportOption } from 'prettier';
import { CATEGORY_PUG } from '.';
import { CATEGORY_PUG } from './constants';

/** Pug print width option. */
export const PUG_PRINT_WIDTH_OPTION: IntSupportOption = {
Expand Down
4 changes: 4 additions & 0 deletions src/options/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* Category for Prettier's CLI.
*/
export const CATEGORY_PUG: string = 'Pug';
2 changes: 1 addition & 1 deletion src/options/converge.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ParserOptions } from 'prettier';
import type { PugParserOptions } from '.';
import type { PugPrinterOptions } from '../printer';
import type { PugParserOptions } from './types';

/**
* Convert and merge options from Prettier and `pug`-specific options into one option object with normalized default values.
Expand Down
12 changes: 7 additions & 5 deletions src/options/empty-attributes/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type { ChoiceSupportOption, PathArraySupportOption } from 'prettier';
import { CATEGORY_PUG } from '..';
import { CATEGORY_PUG } from '../constants';

import type { PugEmptyAttributes } from './types';

/** Pug empty attributes option. */
export const PUG_EMPTY_ATTRIBUTES_OPTION: ChoiceSupportOption<PugEmptyAttributes> =
Expand Down Expand Up @@ -39,7 +41,7 @@ export const PUG_EMPTY_ATTRIBUTES_FORCE_QUOTES_OPTION: PathArraySupportOption =
'Define a list of patterns for attributes that will be forced to have empty quotes even with "none" selected.',
};

/** Pug empty attributes. */
export type PugEmptyAttributes = 'as-is' | 'none' | 'all';
/** Pug empty attributes force quotes. */
export type PugEmptyAttributesForceQuotes = string[];
export type {
PugEmptyAttributes,
PugEmptyAttributesForceQuotes,
} from './types';
4 changes: 4 additions & 0 deletions src/options/empty-attributes/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/** Pug empty attributes. */
export type PugEmptyAttributes = 'as-is' | 'none' | 'all';
/** Pug empty attributes force quotes. */
export type PugEmptyAttributesForceQuotes = string[];
5 changes: 4 additions & 1 deletion src/options/empty-attributes/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import type { AttributeToken } from 'pug-lexer';
import type { PugEmptyAttributes, PugEmptyAttributesForceQuotes } from '.';
import type {
PugEmptyAttributes,
PugEmptyAttributesForceQuotes,
} from './types';

const EMPTY_VALUES: [boolean, string, string] = [true, '""', "''"];

Expand Down
72 changes: 4 additions & 68 deletions src/options/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import type { ParserOptions, SupportOptions } from 'prettier';
import type { PugSortAttributes } from './attribute-sorting';
import type { SupportOptions } from 'prettier';
import {
PUG_SORT_ATTRIBUTES_BEGINNING_OPTION,
PUG_SORT_ATTRIBUTES_END_OPTION,
PUG_SORT_ATTRIBUTES_OPTION,
} from './attribute-sorting';
import type { ArrowParens } from './common';
import {
PUG_ARROW_PARENS_OPTION,
PUG_BRACKET_SAME_LINE_OPTION,
Expand All @@ -16,88 +14,23 @@ import {
PUG_TAB_WIDTH_OPTION,
PUG_USE_TABS_OPTION,
} from './common';
import type {
PugEmptyAttributes,
PugEmptyAttributesForceQuotes,
} from './empty-attributes';
import {
PUG_EMPTY_ATTRIBUTES_FORCE_QUOTES_OPTION,
PUG_EMPTY_ATTRIBUTES_OPTION,
} from './empty-attributes';
import type { PugAttributeSeparator } from './pug-attribute-separator';
import { PUG_ATTRIBUTE_SEPARATOR_OPTION } from './pug-attribute-separator';
import type { PugClassLocation } from './pug-class-location';
import { PUG_CLASS_LOCATION } from './pug-class-location';
import type { PugClassNotation } from './pug-class-notation';
import { PUG_CLASS_NOTATION } from './pug-class-notation';
import type { PugCommentPreserveSpaces } from './pug-comment-preserve-spaces';
import { PUG_COMMENT_PRESERVE_SPACES_OPTION } from './pug-comment-preserve-spaces';
import { PUG_EXPLICIT_DIV } from './pug-explicit-div';
import type { PugFramework } from './pug-framework';
import { PUG_FRAMEWORK } from './pug-framework';
import type { PugIdNotation } from './pug-id-notation';
import { PUG_ID_NOTATION } from './pug-id-notation';
import { PUG_SINGLE_FILE_COMPONENT_INDENTATION } from './pug-single-file-component-indentation';
import {
PUG_WRAP_ATTRIBUTES_PATTERN,
PUG_WRAP_ATTRIBUTES_THRESHOLD,
} from './pug-wrap-attributes';

/**
* Category for Prettier's CLI.
*/
export const CATEGORY_PUG: string = 'Pug';

/**
* Extended pug option object.
*/
export interface PugParserOptions
extends Pick<
ParserOptions,
| 'printWidth'
| 'singleQuote'
| 'tabWidth'
| 'useTabs'
| 'bracketSpacing'
| 'arrowParens'
| 'semi'
| 'bracketSameLine'
> {
pugPrintWidth: number;
pugSingleQuote: boolean | null;
pugTabWidth: number;
pugUseTabs: boolean | null;
pugBracketSpacing: boolean | null;
pugArrowParens: ArrowParens | null;
pugSemi: boolean | null;
pugBracketSameLine: boolean | null;

pugAttributeSeparator: PugAttributeSeparator;

pugCommentPreserveSpaces: PugCommentPreserveSpaces;

pugSortAttributes: PugSortAttributes;
pugSortAttributesBeginning: string[];
pugSortAttributesEnd: string[];

pugWrapAttributesThreshold: number;
pugWrapAttributesPattern: string;

pugClassNotation: PugClassNotation;
pugIdNotation: PugIdNotation;

pugClassLocation: PugClassLocation;

pugExplicitDiv: boolean;

pugEmptyAttributes: PugEmptyAttributes;
pugEmptyAttributesForceQuotes: PugEmptyAttributesForceQuotes;

pugSingleFileComponentIndentation: boolean;

pugFramework: PugFramework;
}

/**
* All supported options by `@prettier/plugin-pug`.
*/
Expand Down Expand Up @@ -126,3 +59,6 @@ export const options: SupportOptions = {
pugSingleFileComponentIndentation: PUG_SINGLE_FILE_COMPONENT_INDENTATION,
pugFramework: PUG_FRAMEWORK,
};

export { CATEGORY_PUG } from './constants';
export type { PugParserOptions } from './types';
2 changes: 1 addition & 1 deletion src/options/pug-attribute-separator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ChoiceSupportOption } from 'prettier';
import { CATEGORY_PUG } from '.';
import { CATEGORY_PUG } from './constants';

/** Pug attribute separator option. */
export const PUG_ATTRIBUTE_SEPARATOR_OPTION: ChoiceSupportOption<PugAttributeSeparator> =
Expand Down
2 changes: 1 addition & 1 deletion src/options/pug-class-location.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ChoiceSupportOption } from 'prettier';
import { CATEGORY_PUG } from '.';
import { CATEGORY_PUG } from './constants';

/** Pug class location. */
export const PUG_CLASS_LOCATION: ChoiceSupportOption = {
Expand Down
2 changes: 1 addition & 1 deletion src/options/pug-class-notation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ChoiceSupportOption } from 'prettier';
import { CATEGORY_PUG } from '.';
import { CATEGORY_PUG } from './constants';

/** Pug class notation. */
export const PUG_CLASS_NOTATION: ChoiceSupportOption = {
Expand Down
2 changes: 1 addition & 1 deletion src/options/pug-comment-preserve-spaces.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ChoiceSupportOption } from 'prettier';
import { CATEGORY_PUG } from '.';
import { CATEGORY_PUG } from './constants';

/** Pug comment preserve spaces option. */
export const PUG_COMMENT_PRESERVE_SPACES_OPTION: ChoiceSupportOption<PugCommentPreserveSpaces> =
Expand Down
2 changes: 1 addition & 1 deletion src/options/pug-explicit-div.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { BooleanSupportOption } from 'prettier';
import { CATEGORY_PUG } from '.';
import { CATEGORY_PUG } from './constants';

/** Pug default div tag. */
export const PUG_EXPLICIT_DIV: BooleanSupportOption = {
Expand Down
2 changes: 1 addition & 1 deletion src/options/pug-framework.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ChoiceSupportOption } from 'prettier';
import { CATEGORY_PUG } from '.';
import { CATEGORY_PUG } from './constants';

/** Pug Framework. */
export const PUG_FRAMEWORK: ChoiceSupportOption<PugFramework> = {
Expand Down
2 changes: 1 addition & 1 deletion src/options/pug-id-notation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ChoiceSupportOption } from 'prettier';
import { CATEGORY_PUG } from '.';
import { CATEGORY_PUG } from './constants';

/** Pug id notation. */
export const PUG_ID_NOTATION: ChoiceSupportOption = {
Expand Down
2 changes: 1 addition & 1 deletion src/options/pug-single-file-component-indentation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { BooleanSupportOption } from 'prettier';
import { CATEGORY_PUG } from '.';
import { CATEGORY_PUG } from './constants';

/** Pug single file component indentation. */
export const PUG_SINGLE_FILE_COMPONENT_INDENTATION: BooleanSupportOption = {
Expand Down
2 changes: 1 addition & 1 deletion src/options/pug-wrap-attributes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { IntSupportOption, PathSupportOption } from 'prettier';
import { CATEGORY_PUG } from '.';
import { CATEGORY_PUG } from './constants';

/** Wrap attributes threshold. */
export const PUG_WRAP_ATTRIBUTES_THRESHOLD: IntSupportOption = {
Expand Down
63 changes: 63 additions & 0 deletions src/options/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import type { ParserOptions } from 'prettier';
import type { PugSortAttributes } from './attribute-sorting';
import type { ArrowParens } from './common';
import type {
PugEmptyAttributes,
PugEmptyAttributesForceQuotes,
} from './empty-attributes';
import type { PugAttributeSeparator } from './pug-attribute-separator';
import type { PugClassLocation } from './pug-class-location';
import type { PugClassNotation } from './pug-class-notation';
import type { PugCommentPreserveSpaces } from './pug-comment-preserve-spaces';
import type { PugFramework } from './pug-framework';
import type { PugIdNotation } from './pug-id-notation';

/**
* Extended pug option object.
*/
export interface PugParserOptions
extends Pick<
ParserOptions,
| 'printWidth'
| 'singleQuote'
| 'tabWidth'
| 'useTabs'
| 'bracketSpacing'
| 'arrowParens'
| 'semi'
| 'bracketSameLine'
> {
pugPrintWidth: number;
pugSingleQuote: boolean | null;
pugTabWidth: number;
pugUseTabs: boolean | null;
pugBracketSpacing: boolean | null;
pugArrowParens: ArrowParens | null;
pugSemi: boolean | null;
pugBracketSameLine: boolean | null;

pugAttributeSeparator: PugAttributeSeparator;

pugCommentPreserveSpaces: PugCommentPreserveSpaces;

pugSortAttributes: PugSortAttributes;
pugSortAttributesBeginning: string[];
pugSortAttributesEnd: string[];

pugWrapAttributesThreshold: number;
pugWrapAttributesPattern: string;

pugClassNotation: PugClassNotation;
pugIdNotation: PugIdNotation;

pugClassLocation: PugClassLocation;

pugExplicitDiv: boolean;

pugEmptyAttributes: PugEmptyAttributes;
pugEmptyAttributesForceQuotes: PugEmptyAttributesForceQuotes;

pugSingleFileComponentIndentation: boolean;

pugFramework: PugFramework;
}