Skip to content

Commit

Permalink
chore: use Biome to format JS files (withastro#10788)
Browse files Browse the repository at this point in the history
* chore: configuration

* chore: update main commands

* chore: revert formatting package.json

* chore: rebase
  • Loading branch information
ematipico authored and PeterDraex committed Apr 23, 2024
1 parent 635d65c commit 6c310f4
Show file tree
Hide file tree
Showing 20 changed files with 175 additions and 118 deletions.
9 changes: 9 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,12 @@ benchmark/results/

# Files
pnpm-lock.yaml

# Formatted by Biome
**/*.json
**/*.js
**/*.ts
**/*.tsx
**/*.jsx
**/*.mjs
**/*.cjs
46 changes: 37 additions & 9 deletions biome.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,44 @@
{
"$schema": "https://biomejs.dev/schemas/1.5.3/schema.json",
"$schema": "https://biomejs.dev/schemas/1.6.4/schema.json",
"files": {
"include": ["test/**", "e2e/**", "packages/**"],
"ignore": ["vendor", "dist/**"]
"ignore": ["vendor", "dist/**"],
"include": ["test/**", "e2e/**", "packages/**"]
},
"organizeImports": {
"enabled": true
"formatter": {
"indentStyle": "tab",
"indentWidth": 2,
"lineWidth": 100,
"ignore": [
"benchmark/projects/",
"benchmark/results/",
"**/dist/**",
"**/smoke/**",
"**/fixtures/**",
"**/vendor/**",
"**/.vercel/**",
".changeset",
"pnpm-lock.yaml",
"package.json",
"*.astro"
]
},
"linter": {
"enabled": false
"organizeImports": { "enabled": true },
"linter": { "enabled": false },
"javascript": {
"formatter": {
"trailingComma": "es5",
"quoteStyle": "single",
"semicolons": "always"
}
},
"formatter": {
"enabled": false
"json": {
"parser": {
"allowComments": true,
"allowTrailingCommas": true
},
"formatter": {
"indentStyle": "space",
"trailingCommas": "none"
}
}
}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"dev": "turbo run dev --concurrency=40 --parallel --filter=astro --filter=create-astro --filter=\"@astrojs/*\" --filter=\"@benchmark/*\"",
"format": "pnpm run format:code && pnpm run format:imports",
"format:ci": "pnpm run format:code:ci && pnpm run format:imports:ci",
"format:code": "prettier -w \"**/*\" --ignore-unknown --cache",
"format:code:ci": "prettier -w \"**/*\" --ignore-unknown --cache --check",
"format:code": "biome format ./ --write && prettier -w \"**/*\" --ignore-unknown --cache",
"format:code:ci": "biome format ./ && prettier -w \"**/*\" --ignore-unknown --cache --check",
"format:imports": "biome check --apply .",
"format:imports:ci": "biome ci .",
"test": "turbo run test --concurrency=1 --filter=astro --filter=create-astro --filter=\"@astrojs/*\"",
Expand Down Expand Up @@ -53,7 +53,7 @@
},
"devDependencies": {
"@astrojs/check": "^0.5.8",
"@biomejs/biome": "1.5.3",
"@biomejs/biome": "1.6.4",
"@changesets/changelog-github": "^0.4.8",
"@changesets/cli": "^2.26.2",
"@eslint/eslintrc": "^3.0.2",
Expand Down
13 changes: 7 additions & 6 deletions packages/astro-rss/test/rss.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,18 @@ import {

// note: I spent 30 minutes looking for a nice node-based snapshot tool
// ...and I gave up. Enjoy big strings!
// prettier-ignore

// biome-ignore format: keep in one line
const validXmlResult = `<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"><channel><title><![CDATA[${title}]]></title><description><![CDATA[${description}]]></description><link>${site}/</link><item><title><![CDATA[${phpFeedItem.title}]]></title><link>${site}${phpFeedItem.link}/</link><guid isPermaLink="true">${site}${phpFeedItem.link}/</guid><description><![CDATA[${phpFeedItem.description}]]></description><pubDate>${new Date(phpFeedItem.pubDate).toUTCString()}</pubDate></item><item><title><![CDATA[${web1FeedItem.title}]]></title><link>${site}${web1FeedItem.link}/</link><guid isPermaLink="true">${site}${web1FeedItem.link}/</guid><description><![CDATA[${web1FeedItem.description}]]></description><pubDate>${new Date(web1FeedItem.pubDate).toUTCString()}</pubDate></item></channel></rss>`;
// prettier-ignore
// biome-ignore format: keep in one line
const validXmlWithContentResult = `<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title><![CDATA[${title}]]></title><description><![CDATA[${description}]]></description><link>${site}/</link><item><title><![CDATA[${phpFeedItemWithContent.title}]]></title><link>${site}${phpFeedItemWithContent.link}/</link><guid isPermaLink="true">${site}${phpFeedItemWithContent.link}/</guid><description><![CDATA[${phpFeedItemWithContent.description}]]></description><pubDate>${new Date(phpFeedItemWithContent.pubDate).toUTCString()}</pubDate><content:encoded><![CDATA[${phpFeedItemWithContent.content}]]></content:encoded></item><item><title><![CDATA[${web1FeedItemWithContent.title}]]></title><link>${site}${web1FeedItemWithContent.link}/</link><guid isPermaLink="true">${site}${web1FeedItemWithContent.link}/</guid><description><![CDATA[${web1FeedItemWithContent.description}]]></description><pubDate>${new Date(web1FeedItemWithContent.pubDate).toUTCString()}</pubDate><content:encoded><![CDATA[${web1FeedItemWithContent.content}]]></content:encoded></item></channel></rss>`;
// prettier-ignore
// biome-ignore format: keep in one line
const validXmlResultWithAllData = `<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"><channel><title><![CDATA[${title}]]></title><description><![CDATA[${description}]]></description><link>${site}/</link><item><title><![CDATA[${phpFeedItem.title}]]></title><link>${site}${phpFeedItem.link}/</link><guid isPermaLink="true">${site}${phpFeedItem.link}/</guid><description><![CDATA[${phpFeedItem.description}]]></description><pubDate>${new Date(phpFeedItem.pubDate).toUTCString()}</pubDate></item><item><title><![CDATA[${web1FeedItemWithAllData.title}]]></title><link>${site}${web1FeedItemWithAllData.link}/</link><guid isPermaLink="true">${site}${web1FeedItemWithAllData.link}/</guid><description><![CDATA[${web1FeedItemWithAllData.description}]]></description><pubDate>${new Date(web1FeedItemWithAllData.pubDate).toUTCString()}</pubDate><category>${web1FeedItemWithAllData.categories[0]}</category><category>${web1FeedItemWithAllData.categories[1]}</category><author>${web1FeedItemWithAllData.author}</author><comments>${web1FeedItemWithAllData.commentsUrl}</comments><source url="${web1FeedItemWithAllData.source.url}">${web1FeedItemWithAllData.source.title}</source><enclosure url="${site}${web1FeedItemWithAllData.enclosure.url}" length="${web1FeedItemWithAllData.enclosure.length}" type="${web1FeedItemWithAllData.enclosure.type}"/></item></channel></rss>`;
// prettier-ignore
// biome-ignore format: keep in one line
const validXmlWithCustomDataResult = `<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title><![CDATA[${title}]]></title><description><![CDATA[${description}]]></description><link>${site}/</link><item><title><![CDATA[${phpFeedItemWithCustomData.title}]]></title><link>${site}${phpFeedItemWithCustomData.link}/</link><guid isPermaLink="true">${site}${phpFeedItemWithCustomData.link}/</guid><description><![CDATA[${phpFeedItemWithCustomData.description}]]></description><pubDate>${new Date(phpFeedItemWithCustomData.pubDate).toUTCString()}</pubDate>${phpFeedItemWithCustomData.customData}</item><item><title><![CDATA[${web1FeedItemWithContent.title}]]></title><link>${site}${web1FeedItemWithContent.link}/</link><guid isPermaLink="true">${site}${web1FeedItemWithContent.link}/</guid><description><![CDATA[${web1FeedItemWithContent.description}]]></description><pubDate>${new Date(web1FeedItemWithContent.pubDate).toUTCString()}</pubDate><content:encoded><![CDATA[${web1FeedItemWithContent.content}]]></content:encoded></item></channel></rss>`;
// prettier-ignore
// biome-ignore format: keep in one line
const validXmlWithStylesheet = `<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet href="/feedstylesheet.css"?><rss version="2.0"><channel><title><![CDATA[${title}]]></title><description><![CDATA[${description}]]></description><link>${site}/</link></channel></rss>`;
// prettier-ignore
// biome-ignore format: keep in one line
const validXmlWithXSLStylesheet = `<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet href="/feedstylesheet.xsl" type="text/xsl"?><rss version="2.0"><channel><title><![CDATA[${title}]]></title><description><![CDATA[${description}]]></description><link>${site}/</link></channel></rss>`;

function assertXmlDeepEqual(a, b) {
Expand Down
2 changes: 0 additions & 2 deletions packages/astro/astro-jsx.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
* Adapted from React’s TypeScript definition from DefinitelyTyped.
* @see https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/react/index.d.ts
*/
// BUG! Prettier 3.0 removes `declare`: https://github.com/prettier/prettier/issues/15207
// prettier-ignore
declare namespace astroHTML.JSX {
export type Child = Node | Node[] | string | number | boolean | null | undefined | unknown;
export type Children = Child | Child[];
Expand Down
81 changes: 40 additions & 41 deletions packages/astro/src/@types/astro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1496,9 +1496,8 @@ export interface AstroUserConfig {
* Controls the routing strategy to determine your site URLs. Set this based on your folder/URL path configuration for your default language.
*
*/
// prettier-ignore
routing?:
{
routing?:
| {
/**
* @docs
* @name i18n.routing.prefixDefaultLocale
Expand All @@ -1515,18 +1514,18 @@ export interface AstroUserConfig {
* When `true`, all URLs will display a language prefix.
* URLs will be of the form `example.com/[locale]/content/` for every route, including the default language.
* Localized folders are used for every language, including the default.
*
* ```js
* export default defineConfig({
* i18n: {
* defaultLocale: "en",
* locales: ["en", "fr", "pt-br", "es"],
* routing: {
* prefixDefaultLocale: true,
* }
* }
* })
* ```
*
* ```js
* export default defineConfig({
* i18n: {
* defaultLocale: "en",
* locales: ["en", "fr", "pt-br", "es"],
* routing: {
* prefixDefaultLocale: true,
* }
* }
* })
* ```
*/
prefixDefaultLocale?: boolean;

Expand Down Expand Up @@ -1569,32 +1568,32 @@ export interface AstroUserConfig {
* - `"pathname": The strategy is applied to the pathname of the URLs
*/
strategy?: 'pathname';
} |
/**
*
* @docs
* @name i18n.routing.manual
* @kind h4
* @type {string}
* @version 4.6.0
* @description
* When this option is enabled, Astro will **disable** its i18n middleware so that you can implement your own custom logic. No other `routing` options (e.g. `prefixDefaultLocale`) may be configured with `routing: "manual"`.
*
* You will be responsible for writing your own routing logic, or executing Astro's i18n middleware manually alongside your own.
*
* ```js
* export default defineConfig({
* i18n: {
* defaultLocale: "en",
* locales: ["en", "fr", "pt-br", "es"],
* routing: {
* prefixDefaultLocale: true,
* }
* }
* })
* ```
*/
'manual';
}
/**
*
* @docs
* @name i18n.routing.manual
* @kind h4
* @type {string}
* @version 4.6.0
* @description
* When this option is enabled, Astro will **disable** its i18n middleware so that you can implement your own custom logic. No other `routing` options (e.g. `prefixDefaultLocale`) may be configured with `routing: "manual"`.
*
* You will be responsible for writing your own routing logic, or executing Astro's i18n middleware manually alongside your own.
*
* ```js
* export default defineConfig({
* i18n: {
* defaultLocale: "en",
* locales: ["en", "fr", "pt-br", "es"],
* routing: {
* prefixDefaultLocale: true,
* }
* }
* })
* ```
*/
| 'manual';

/**
* @name i18n.domains
Expand Down
4 changes: 3 additions & 1 deletion packages/astro/src/assets/vite-plugin-assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ export default function assets({
: settings.config.outDir
)
)});
export const assetsDir = /* #__PURE__ */ new URL(${JSON.stringify(settings.config.build.assets)}, outDir);
export const assetsDir = /* #__PURE__ */ new URL(${JSON.stringify(
settings.config.build.assets
)}, outDir);
export const getImage = async (options) => await getImageInternal(options, imageConfig);
`;
}
Expand Down
4 changes: 3 additions & 1 deletion packages/astro/src/cli/install-package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ export async function getPackage<T>(
return packageImport as T;
} catch (e) {
if (options.optional) return undefined;
let message = `To continue, Astro requires the following dependency to be installed: ${bold(packageName)}.`;
let message = `To continue, Astro requires the following dependency to be installed: ${bold(
packageName
)}.`;

if (ci.isCI) {
message += ` Packages cannot be installed automatically in CI environments.`;
Expand Down
4 changes: 3 additions & 1 deletion packages/astro/src/core/errors/dev/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,9 @@ function collectInfoFromStacktrace(error: SSRError & { stack: string }): StackIn
error.pluginCode ||
error.id ||
// TODO: this could be better, `src` might be something else
stackText.split('\n').find((ln) => ln.includes('src') || ln.includes('node_modules'));
stackText
.split('\n')
.find((ln) => ln.includes('src') || ln.includes('node_modules'));
// Disable eslint as we're not sure how to improve this regex yet
// eslint-disable-next-line regexp/no-super-linear-backtracking
const source = possibleFilePath?.replace?.(/^[^(]+\(([^)]+).*$/, '$1').replace(/^\s+at\s+/, '');
Expand Down
4 changes: 1 addition & 3 deletions packages/astro/src/core/errors/errors-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,7 @@ export const NoMatchingRenderer = {
${
validRenderersCount > 0
? `There ${plural ? 'are' : 'is'} ${validRenderersCount} renderer${
plural ? 's' : ''
} configured in your \`astro.config.mjs\` file,
? `There ${plural ? 'are' : 'is'} ${validRenderersCount} renderer${plural ? 's' : ''} configured in your \`astro.config.mjs\` file,
but ${plural ? 'none were' : 'it was not'} able to server-side render \`${componentName}\`.`
: `No valid renderer was found ${
componentExtension
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,9 @@ export default {
if (placement === settings.config[setting.settingKey]) {
option.selected = true;
}
option.textContent =
`${placement.slice(0, 1).toUpperCase()}${placement.slice(1)}`.replace('-', ' ');
option.textContent = `${placement.slice(0, 1).toUpperCase()}${placement.slice(
1
)}`.replace('-', ' ');
astroSelect.append(option);
});
astroSelect.element.addEventListener('change', setting.changeEvent);
Expand Down
8 changes: 6 additions & 2 deletions packages/astro/src/runtime/client/dev-toolbar/toolbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,9 @@ export class AstroDevToolbar extends HTMLElement {
width: 1px;
}
</style>
<div id="dev-toolbar-root" data-hidden ${settings.config.disableAppNotification ? 'data-no-notification' : ''} data-placement="${settings.config.placement}">
<div id="dev-toolbar-root" data-hidden ${
settings.config.disableAppNotification ? 'data-no-notification' : ''
} data-placement="${settings.config.placement}">
<div id="dev-bar-hitbox-above"></div>
<div id="dev-bar">
<div id="bar-container">
Expand All @@ -281,7 +283,9 @@ export class AstroDevToolbar extends HTMLElement {
: ''
}
<div class="separator"></div>
${this.getAppTemplate(this.apps.find((app) => app.builtIn && app.id === 'astro:settings')!)}
${this.getAppTemplate(
this.apps.find((app) => app.builtIn && app.id === 'astro:settings')!
)}
</div>
</div>
<div id="dev-bar-hitbox-below"></div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,11 @@ export class DevToolbarTooltip extends HTMLElement {
: ''
}
${section.content ? `<div class="section-content">${section.content}</div>` : ''}
${section.clickDescription ? `<span class="modal-cta">${section.clickDescription}</span>` : ''}
${
section.clickDescription
? `<span class="modal-cta">${section.clickDescription}</span>`
: ''
}
`;
fragment.append(sectionElement);

Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/transitions/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ async function transition(
preparationEvent.sourceElement instanceof HTMLFormElement
? preparationEvent.sourceElement
: preparationEvent.sourceElement instanceof HTMLElement &&
'form' in preparationEvent.sourceElement
'form' in preparationEvent.sourceElement
? (preparationEvent.sourceElement.form as HTMLFormElement)
: preparationEvent.sourceElement?.closest('form');
// Form elements without enctype explicitly set default to application/x-www-form-urlencoded.
Expand Down
6 changes: 5 additions & 1 deletion packages/astro/test/test-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ export default function (
return new Response(data);
}
${provideAddress ? `request[Symbol.for('astro.clientAddress')] = '0.0.0.0';` : ''}
${
provideAddress
? `request[Symbol.for('astro.clientAddress')] = '0.0.0.0';`
: ''
}
return super.render(request, routeData, locals);
}
}
Expand Down
3 changes: 1 addition & 2 deletions packages/db/src/core/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ export const RENAME_COLUMN_ERROR = (oldSelector: string, newSelector: string) =>
);
};

export const FILE_NOT_FOUND_ERROR = (path: string) =>
`${red('▶ File not found:')} ${bold(path)}\n`;
export const FILE_NOT_FOUND_ERROR = (path: string) => `${red('▶ File not found:')} ${bold(path)}\n`;

export const SHELL_QUERY_MISSING_ERROR = `${red(
'▶ Please provide a query to execute using the --query flag.'
Expand Down
4 changes: 3 additions & 1 deletion packages/db/src/core/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ export const dateColumnSchema = z.object({
.union([
sqlSchema,
// transform to ISO string for serialization
z.date().transform((d) => d.toISOString()),
z
.date()
.transform((d) => d.toISOString()),
])
.optional(),
}),
Expand Down
6 changes: 5 additions & 1 deletion packages/upgrade/src/actions/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ export async function getContext(argv: string[]): Promise<Context> {
);

const packageManager = detectPackageManager()?.name ?? 'npm';
const { _: [version = 'latest'] = [], '--help': help = false, '--dry-run': dryRun } = flags;
const {
_: [version = 'latest'] = [],
'--help': help = false,
'--dry-run': dryRun,
} = flags;

return {
help,
Expand Down
Loading

0 comments on commit 6c310f4

Please sign in to comment.