Skip to content

Commit

Permalink
refactor: reformat sources using prettier
Browse files Browse the repository at this point in the history
used "prettify" script
  • Loading branch information
AviVahl committed Jan 3, 2025
1 parent 895db66 commit 1cb0efa
Show file tree
Hide file tree
Showing 41 changed files with 255 additions and 233 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
node-version-file: .nvmrc
registry-url: 'https://registry.npmjs.org/'
cache: npm
- run: npm ci
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
node-version-file: .nvmrc
cache: npm
- run: npm ci
- run: npm test
6 changes: 3 additions & 3 deletions demos/client/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export function initPreview(
input: HTMLTextAreaElement,
output: HTMLElement,
tokenizeValues: (value: string) => any[],
renderer = renderShallowToken
renderer = renderShallowToken,
) {
const render = true;
let start = 0;
Expand Down Expand Up @@ -52,7 +52,7 @@ export function renderToken(
token: any,
range: { start: number; end: number },
level = 0,
parentInRange = false
parentInRange = false,
) {
const isArray = Array.isArray(token);
const open = isArray ? '[' : '{';
Expand Down Expand Up @@ -87,7 +87,7 @@ export function renderNestedToken(range: {

export function isInRange(
token: { start: number; end: number },
range: { start: number; end: number }
range: { start: number; end: number },
) {
if (range.end === range.start) {
if (token.start <= range.start && range.start < token.end) {
Expand Down
2 changes: 1 addition & 1 deletion demos/css-selector-parser.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
Expand Down
2 changes: 1 addition & 1 deletion demos/css-value-syntax-parser.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
Expand Down
2 changes: 1 addition & 1 deletion demos/css-value-tokenizer.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
Expand Down
2 changes: 1 addition & 1 deletion demos/import-tokenizer.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<title>Tokens</title>
Expand Down
4 changes: 2 additions & 2 deletions demos/separated-shallow-list.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
Expand Down Expand Up @@ -47,7 +47,7 @@
initPreview(input, output, (value) =>
getListItems(value, (char) => {
return JSON.parse(`"${seps.value}"`).includes(char);
})
}),
);
</script>
</body>
Expand Down
2 changes: 1 addition & 1 deletion demos/tokey-tokenizer.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
Expand Down
2 changes: 1 addition & 1 deletion demos/url-tokenizer.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
Expand Down
54 changes: 27 additions & 27 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,37 @@ import pluginNoOnlyTests from 'eslint-plugin-no-only-tests';
import pluginTypescript from 'typescript-eslint';

for (const config of pluginTypescript.configs.recommendedTypeChecked) {
config.files = ['**/*.{ts,tsx,mts,cts}']; // ensure config only targets TypeScript files
config.files = ['**/*.{ts,tsx,mts,cts}']; // ensure config only targets TypeScript files
}

/** @type {import('eslint').Linter.Config[]} */
export default [
{ ignores: ['**/dist/'] },
pluginJs.configs.recommended,
{ plugins: { 'no-only-tests': pluginNoOnlyTests } },
{
rules: {
// 'no-console': 'error',
'no-only-tests/no-only-tests': 'error',
'no-undef': 'off',
'no-unused-vars': ['error', { argsIgnorePattern: '^_', varsIgnorePattern: '^_' }],
},
{ ignores: ['**/dist/'] },
pluginJs.configs.recommended,
{ plugins: { 'no-only-tests': pluginNoOnlyTests } },
{
rules: {
// 'no-console': 'error',
'no-only-tests/no-only-tests': 'error',
'no-undef': 'off',
'no-unused-vars': ['error', { argsIgnorePattern: '^_', varsIgnorePattern: '^_' }],
},
...pluginTypescript.configs.recommendedTypeChecked,
{ languageOptions: { parserOptions: { projectService: true } } },
{
files: ['**/*.{ts,tsx,mts,cts}'],
rules: {
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/no-unsafe-return": "off",
"@typescript-eslint/unbound-method": "off",
'@typescript-eslint/no-unused-vars': [
'error',
{ argsIgnorePattern: '^_', varsIgnorePattern: '^_' },
],
},
},
...pluginTypescript.configs.recommendedTypeChecked,
{ languageOptions: { parserOptions: { projectService: true } } },
{
files: ['**/*.{ts,tsx,mts,cts}'],
rules: {
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/unbound-method': 'off',
'@typescript-eslint/no-unused-vars': [
'error',
{ argsIgnorePattern: '^_', varsIgnorePattern: '^_' },
],
},
configPrettier,
},
configPrettier,
];
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"lint": "eslint",
"pretest": "npm run lint && npm run build",
"test": "mocha \"./packages/*/dist/test/**/*.spec.js\"",
"prettify": "npx prettier . --write",
"prettify": "prettier . --write",
"start": "node scripts/dev-server.js"
},
"devDependencies": {
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface TokyOptions<T extends Token<unknown>> {
ch: string,
source: string,
nextCharIndex: number,
previousChar: string
previousChar: string,
): boolean;
getUnclosedComment(inComment: string): string;
createToken(value: string, type: T['type'], start: number, end: number): T;
Expand All @@ -32,7 +32,7 @@ export function tokenize<T extends Token<unknown>>(
isCommentEnd,
getUnclosedComment,
offset = 0,
}: TokyOptions<T>
}: TokyOptions<T>,
): T[] {
const tokens: T[] = [];
let previousChar = '';
Expand Down Expand Up @@ -72,7 +72,7 @@ export function tokenize<T extends Token<unknown>>(
} else if (!isWhitespace(ch) && isWhitespace(previousChar)) {
pushBuffer();
buffer += ch;
} else if(shouldClose?.(ch, previousChar)) {
} else if (shouldClose?.(ch, previousChar)) {
pushBuffer();
buffer += ch;
pushBuffer(ch);
Expand Down
12 changes: 6 additions & 6 deletions packages/core/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const createToken = <Type extends string>(
value: string,
type: Type,
start: number,
end: number
end: number,
) => {
return {
value,
Expand All @@ -48,7 +48,7 @@ export const createToken = <Type extends string>(
export function getJSCommentStartType(
ch: string,
source: string,
nextCharIndex: number
nextCharIndex: number,
): '' | 'line-comment' | 'multi-comment' {
if (ch === '/' && source[nextCharIndex] === '/') {
return 'line-comment';
Expand All @@ -63,7 +63,7 @@ export function getJSCommentStartType(
export function getMultilineCommentStartType(
ch: string,
source: string,
nextCharIndex: number
nextCharIndex: number,
): '' | 'multi-comment' {
return ch === '/' && source[nextCharIndex] === '*' ? 'multi-comment' : '';
}
Expand All @@ -76,7 +76,7 @@ export function isCommentEnd(
ch: string,
_source: string,
_nextCharIndex: number,
previousChar: string
previousChar: string,
): boolean {
if (commentType === 'line-comment' && ch === '\n') {
return true;
Expand Down Expand Up @@ -128,7 +128,7 @@ export function getText(tokens: Token<any>[], startIndex = 0, upToIndex = -1, so
export function groupTokens<Tokens extends Token<any>[], T extends string = 'tokens'>(
tokens: Tokens,
type: T = 'tokens' as T,
source?: string
source?: string,
) {
return {
type,
Expand All @@ -144,7 +144,7 @@ export function groupTokens<Tokens extends Token<any>[], T extends string = 'tok
*/
export function trimTokens<Tokens extends Token<any>[]>(
tokens: Tokens,
shouldTrimToken: (token: Token<any>) => boolean
shouldTrimToken: (token: Token<any>) => boolean,
) {
let start = 0;
let end = tokens.length;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/seeker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export class Seeker<T extends Token<unknown>> {
run<A>(
handleToken: (token: T, ast: A, source: string, seeker: this) => void | boolean,
ast: A,
source: string
source: string,
) {
let token;
while ((token = this.next()) && token.type) {
Expand Down
14 changes: 7 additions & 7 deletions packages/core/test/helpers/trim-tokens.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe(`helpers/trim-tokens`, () => {
{ end: 0, start: 0, type: 'space', value: ' ' },
]),
trimSpace,
[{ end: 0, start: 0, type: 'text', value: 'value' }]
[{ end: 0, start: 0, type: 'text', value: 'value' }],
);
});
it(`should remove single before & after`, () => {
Expand All @@ -36,7 +36,7 @@ describe(`helpers/trim-tokens`, () => {
{ end: 0, start: 0, type: 'space', value: ' ' },
]),
trimSpace,
[{ end: 0, start: 0, type: 'text', value: 'value' }]
[{ end: 0, start: 0, type: 'text', value: 'value' }],
);
});
it(`should remove single after`, () => {
Expand All @@ -46,7 +46,7 @@ describe(`helpers/trim-tokens`, () => {
{ end: 0, start: 0, type: 'space', value: ' ' },
]),
trimSpace,
[{ end: 0, start: 0, type: 'text', value: 'value' }]
[{ end: 0, start: 0, type: 'text', value: 'value' }],
);
});
it(`should remove single before `, () => {
Expand All @@ -56,7 +56,7 @@ describe(`helpers/trim-tokens`, () => {
{ end: 0, start: 0, type: 'text', value: 'value' },
]),
trimSpace,
[{ end: 0, start: 0, type: 'text', value: 'value' }]
[{ end: 0, start: 0, type: 'text', value: 'value' }],
);
});
it(`should not trim when there is nothing to trim`, () => {
Expand All @@ -73,7 +73,7 @@ describe(`helpers/trim-tokens`, () => {
{ end: 0, start: 0, type: 'space', value: ' ' },
]),
trimSpace,
[]
[],
);
});
it(`should trim all when all is "trimmable" (single)`, () => {
Expand All @@ -89,7 +89,7 @@ describe(`helpers/trim-tokens`, () => {
{ end: 0, start: 0, type: 'space', value: ' ' },
]),
trimSpace,
[{ end: 0, start: 0, type: 'text', value: 'value' }]
[{ end: 0, start: 0, type: 'text', value: 'value' }],
);
});
it(`should remove multiple before`, () => {
Expand All @@ -102,7 +102,7 @@ describe(`helpers/trim-tokens`, () => {
{ end: 0, start: 0, type: 'text', value: 'value' },
]),
trimSpace,
[{ end: 0, start: 0, type: 'text', value: 'value' }]
[{ end: 0, start: 0, type: 'text', value: 'value' }],
);
});
});
20 changes: 10 additions & 10 deletions packages/css-selector-parser/src/ast-tools/compound.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,25 @@ export interface GroupCompoundOptions {
}
export function groupCompoundSelectors<AST extends Selector>(
input: AST,
options?: GroupCompoundOptions
options?: GroupCompoundOptions,
): Selector;
export function groupCompoundSelectors<AST extends ImmutableSelector>(
input: AST,
options?: GroupCompoundOptions
options?: GroupCompoundOptions,
): ImmutableSelector;
export function groupCompoundSelectors<AST extends SelectorList>(
input: AST,
options?: GroupCompoundOptions
options?: GroupCompoundOptions,
): SelectorList;
export function groupCompoundSelectors<AST extends ImmutableSelectorList>(
input: AST,
options?: GroupCompoundOptions
options?: GroupCompoundOptions,
): ImmutableSelectorList;
export function groupCompoundSelectors<
AST extends Selector | ImmutableSelector | SelectorList | ImmutableSelectorList
AST extends Selector | ImmutableSelector | SelectorList | ImmutableSelectorList,
>(
input: AST,
options?: GroupCompoundOptions
options?: GroupCompoundOptions,
): Selector | ImmutableSelector | SelectorList | ImmutableSelectorList {
const context = createCompoundContext(options);
walk(input, (node, _index, _nodes, parents) => {
Expand All @@ -52,7 +52,7 @@ export function groupCompoundSelectors<
nodes.push(
nested.type === `selector`
? groupCompoundSelectors(nested, options)
: nested
: nested,
);
}
node = { ...node, nodes };
Expand Down Expand Up @@ -150,14 +150,14 @@ function createCompoundContext({ splitPseudoElements = true }: GroupCompoundOpti

export function splitCompoundSelectors<AST extends Selector>(input: AST): Selector;
export function splitCompoundSelectors<AST extends ImmutableSelector>(
input: AST
input: AST,
): ImmutableSelector;
export function splitCompoundSelectors<AST extends SelectorList>(input: AST): SelectorList;
export function splitCompoundSelectors<AST extends ImmutableSelectorList>(
input: AST
input: AST,
): ImmutableSelectorList;
export function splitCompoundSelectors<AST extends SelectorList | Selector>(
input: AST
input: AST,
): SelectorList | Selector | ImmutableSelector | ImmutableSelectorList {
const inputSelectors: SelectorList = Array.isArray(input) ? input : [input];
const output: SelectorList = [];
Expand Down
2 changes: 1 addition & 1 deletion packages/css-selector-parser/src/ast-tools/specificity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export type Specificity = [
inlineLevel: number,
idLevel: number,
classOrAttributeLevel: number,
typeOrElementLevel: number
typeOrElementLevel: number,
];
export function calcSpecificity(ast: ImmutableSelectorNode): Specificity {
const result: Specificity = [0, 0, 0, 0];
Expand Down
Loading

0 comments on commit 1cb0efa

Please sign in to comment.