Skip to content

Commit

Permalink
Lint files
Browse files Browse the repository at this point in the history
  • Loading branch information
titouanmathis committed Oct 3, 2024
1 parent 40493e8 commit e1f42b8
Show file tree
Hide file tree
Showing 16 changed files with 47 additions and 54 deletions.
3 changes: 3 additions & 0 deletions packages/demo/src/templates/pages/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* @returns {Promise<object>}
*/
export async function data() {
return {
head: {
Expand Down
3 changes: 3 additions & 0 deletions packages/demo/src/templates/pages/posts/[slug].js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
*
*/
export async function data({ slug } = {}) {
return {
bar: 'This is the default post data loader',
Expand Down
3 changes: 3 additions & 0 deletions packages/demo/src/templates/pages/posts/bar.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { data as defaultData } from './[slug].js';

/**
*
*/
export async function data({ slug } = {}) {
const mainData = await defaultData({ slug });
return {
Expand Down
3 changes: 3 additions & 0 deletions packages/demo/src/templates/pages/posts/hello-world.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* @returns {Promise<{ foo: string[] }>}
*/
export async function data() {
return {
foo: ['foo', 'buz'],
Expand Down
11 changes: 1 addition & 10 deletions packages/preset-prototyping/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,27 +148,22 @@ export function prototyping(options) {

const extendTwig = typeof opts.twig.extend === 'function' ? opts.twig.extend : () => {};
opts.twig.functions = {
...(opts?.twig?.functions || {}),
// eslint-disable-next-line camelcase
...opts?.twig?.functions,
html_styles(styles) {
return Html.renderStyleAttribute(styles);
},
// eslint-disable-next-line camelcase
html_attributes(attributes) {
return Html.renderAttributes(attributes);
},
// eslint-disable-next-line camelcase
html_classes(classes) {
return Html.renderClass(classes);
},
// eslint-disable-next-line camelcase
merge_html_attributes(attributes = {}, defaultAttributes = {}, requiredAttributes = {}) {
return Html.mergeAttributes(attributes, defaultAttributes, requiredAttributes);
},
dump(...args) {
return args.map((arg) => `<pre>${JSON.stringify(arg, null, 2)}</pre>`).join('\n');
},
// eslint-disable-next-line camelcase
is_dev() {
return isDev;
},
Expand Down Expand Up @@ -298,9 +293,7 @@ export function prototyping(options) {
cache: true,
template: `${templatePath}?${params}`,
templateParameters: {
// eslint-disable-next-line camelcase
updated_at: stats.mtime,
// eslint-disable-next-line camelcase
created_at: stats.birthtime,
template: file,
...Object.fromEntries(params.entries()),
Expand Down Expand Up @@ -366,9 +359,7 @@ export function prototyping(options) {
cache: true,
template: `${templatePath}?${params}`,
templateParameters: {
// eslint-disable-next-line camelcase
created_at: stats.birthtime,
// eslint-disable-next-line camelcase
updated_at: stats.mtime,
template: file,
...Object.fromEntries(params.entries()),
Expand Down
6 changes: 3 additions & 3 deletions packages/webpack-config/src/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default async function dev(options = {}) {
const server = await getServer(config);

const webpackBar = webpackConfig.plugins.find(
(plugin) => plugin.constructor.name === 'WebpackBarPlugin'
(plugin) => plugin.constructor.name === 'WebpackBarPlugin',
);

let webpackBarHasRunOnce = false;
Expand Down Expand Up @@ -68,7 +68,7 @@ export default async function dev(options = {}) {
Object.entries(webpackConfig.entry).map(([name, value]) => [
name,
['webpack-hot-middleware/client?reload=true', ...(Array.isArray(value) ? value : [value])],
])
]),
);

const bundler = webpack(webpackConfig);
Expand All @@ -84,7 +84,7 @@ export default async function dev(options = {}) {
assets: true,
colors: true,
excludeAssets: [/\.map$/, /hot-update/, /^manifest\.(js|json)$/],
})
}),
);
console.log('');
console.log('');
Expand Down
6 changes: 2 additions & 4 deletions packages/webpack-config/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ const {

/**
* Define the configuration.
*
* @template {import('./index').MetaConfig} T
* @param {T} config
* @returns {T}
Expand All @@ -49,13 +48,12 @@ export function defineConfig(config) {

/**
* Get the generated Webpack configuration.
*
* @param {Object} options
* @param {object} options
* @param {'production'|'development'} [options.mode]
* @returns {import('webpack').Configuration}
*/
export function getWebpackConfig({ mode = process.env.NODE_ENV } = {}) {
const config = getMetaConfig({ target: [target] });
const config = getMetaConfig({ mode });
return mode === 'production' ? getWebpackProdConfig(config) : getWebpackDevConfig(config);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/webpack-config/src/presets/https.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function createCertificates() {

const cachePath = path.join(
process.env.PWD,
'node_modules/.cache/@studiometa/webpack-config/certificates/'
'node_modules/.cache/@studiometa/webpack-config/certificates/',
);

execSync(`mkdir -p ${cachePath}`);
Expand Down
9 changes: 4 additions & 5 deletions packages/webpack-config/src/presets/tailwindcss.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@ export default function tailwindcss(options = {}) {
path: require.resolve('tailwindcss', { paths: [configPath] }),
configViewerPath: '/_tailwind',
},
options
options,
);

if (isDev) {
const { default: createServer } = await import('tailwind-config-viewer/server/index.js');
await extendBrowsersync(config, async (bsConfig) => {
const tailwindConfigViewerServer = createServer({
tailwindConfigProvider: () =>
// eslint-disable-next-line import/no-dynamic-require
require(findUpSync(['tailwind.config.js', 'tailwind.config.cjs'])),
}).asMiddleware();

Expand All @@ -44,8 +43,8 @@ export default function tailwindcss(options = {}) {
bsConfig.infos.push(
(url) =>
`Tailwind Viewer runnning at ${chalk.blue(
withTrailingSlash(url + opts.configViewerPath)
)}`
withTrailingSlash(url + opts.configViewerPath),
)}`,
);
});
}
Expand Down Expand Up @@ -76,7 +75,7 @@ export default function tailwindcss(options = {}) {
}

const postcssIndex = rule.use.findIndex(
(use) => use === 'postcss-loader' || use.loader === 'postcss-loader'
(use) => use === 'postcss-loader' || use.loader === 'postcss-loader',
);

if (postcssIndex > -1) {
Expand Down
2 changes: 1 addition & 1 deletion packages/webpack-config/src/presets/yaml.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default function yaml(options = {}) {
{
loaderOptions: {},
},
options
options,
);

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

/**
* Extends the `server` configuration property.
*
* @param {MetaConfig} config
* @param {(config:BrowsersyncOptions, instance:BrowserSyncInstance)=> void} fn
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/webpack-config/src/utils/extend-webpack-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

/**
* Extends the `webpack` configuration property.
*
* @param {MetaConfig} config
* @param {(config:WebpackConfig, isDev: boolean) => Promise<void>} fn
*/
export default async function extendWebpackConfig(config, fn) {
// eslint-disable-next-line no-empty-function
const oldWebpackConfig = typeof config.webpack === 'function' ? config.webpack : () => {};

config.webpack = async (webpackConfig, isDev) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/webpack-config/src/utils/get-browsersync.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async function getConfig(metaConfig) {
const [fileGlob, callback] = glob;
if (typeof callback !== 'function') {
throw new Error(
'A watch item should implement the following schema: [glob:string, callback:function]'
'A watch item should implement the following schema: [glob:string, callback:function]',
);
}
instance.watch(fileGlob, { cwd: metaConfig.context }, (event, file) => {
Expand Down
9 changes: 3 additions & 6 deletions packages/webpack-config/src/utils/get-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import extendWebpack from './extend-webpack-config.js';

/**
* Get config from meta.config.js file.
*
* @param {{ analyze: boolean, mode: 'development'|'production' }} [options] CLI Options.
* @returns {import('../index').MetaConfig}
*/
Expand All @@ -17,7 +16,7 @@ export default async function getConfig({ analyze = false, mode = 'production' }
[
'Could not find a config file.',
'Is there a meta.config.js file up in the folder tree?',
].join('\n')
].join('\n'),
);
}

Expand Down Expand Up @@ -45,25 +44,23 @@ export default async function getConfig({ analyze = false, mode = 'production' }
if (Array.isArray(config.presets) && config.presets.length) {
console.log('Applying presets...');

// eslint-disable-next-line no-restricted-syntax
for (let preset of config.presets) {
if (typeof preset === 'function') {
preset = preset(isDev);
}

if (!preset) {
// eslint-disable-next-line no-continue
continue;
}

if (!preset.name && typeof preset.handler !== 'function') {
console.log('Preset misconfigured.', preset);
// eslint-disable-next-line no-continue

continue;
}

const start = performance.now();
// eslint-disable-next-line no-await-in-loop

await preset.handler(config, {
extendBrowsersync,
extendWebpack,
Expand Down
14 changes: 7 additions & 7 deletions packages/webpack-config/src/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Test if the given input has a trailing slash.
* @param {string = ''} input The string to test.
* @param {string} [input] The string to test.
* @returns {boolean}
*/
export function hasTrailingSlash(input = '') {
Expand All @@ -9,7 +9,7 @@ export function hasTrailingSlash(input = '') {

/**
* Make sure that a string does not end with a trailing slash.
* @param {string = ''} input The string to test.
* @param {string} [input] The string to test.
* @returns {string} The string without trailing slash.
*/
export function withoutTrailingSlash(input = '') {
Expand All @@ -18,7 +18,7 @@ export function withoutTrailingSlash(input = '') {

/**
* Make sure the string given ends with a trailing slash.
* @param {string = ''} input The string to test.
* @param {string} [input] The string to test.
* @returns {string} The string with a trailing slash.
*/
export function withTrailingSlash(input = '') {
Expand All @@ -27,7 +27,7 @@ export function withTrailingSlash(input = '') {

/**
* Test if the given input has a leading slash.
* @param {string = ''} input The string to test.
* @param {string} [input] The string to test.
* @returns {boolean}
*/
export function hasLeadingSlash(input = '') {
Expand All @@ -36,7 +36,7 @@ export function hasLeadingSlash(input = '') {

/**
* Make sure the given string does not have a leading slash.
* @param {string = ''} input The string to test.
* @param {string} [input] The string to test.
* @returns {string} The string without leading slash.
*/
export function withoutLeadingSlash(input = '') {
Expand All @@ -45,8 +45,8 @@ export function withoutLeadingSlash(input = '') {

/**
* Make sure the given string has a leading slash.
* @param {string = ''} input The string to test.
* @param {string} The string with a leading slash.
* @param {string} [input] The string to test.
* @returns {string} The string with a leading slash.
*/
export function withLeadingSlash(input = '') {
return hasLeadingSlash(input) ? input : `/${input}`;
Expand Down
25 changes: 11 additions & 14 deletions packages/webpack-config/src/webpack.base.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export default async function getWebpackBaseConfig(config, { mode = 'production'
loader: 'sass-loader',
options: {
sassOptions: {
...(config.sassOptions ?? {}),
...config.sassOptions,
// This fix a strange bug where `url()` are not resolved
// by Webpack when the output is set to `compressed` in
// production mode.
Expand Down Expand Up @@ -205,20 +205,17 @@ export default async function getWebpackBaseConfig(config, { mode = 'production'
entrypointsUseAssets: true,
}),
// Do not resolve URL starting with `/` in Sass and CSS files
new ExternalsPlugin(
'module',
({ context, request, dependencyType, contextInfo }, callback) => {
if (
dependencyType === 'url' &&
request.startsWith('/') &&
CSS_FILE_REGEXP.test(contextInfo.issuer)
) {
return callback(null, `asset ${request}`);
}
new ExternalsPlugin('module', ({ request, dependencyType, contextInfo }, callback) => {
if (
dependencyType === 'url' &&
request.startsWith('/') &&
CSS_FILE_REGEXP.test(contextInfo.issuer)
) {
return callback(null, `asset ${request}`);
}

callback();
},
),
callback();
}),
],
optimization: {
minimizer: [
Expand Down

0 comments on commit e1f42b8

Please sign in to comment.