Skip to content

Commit

Permalink
add ESLint rules for whitespace linting (#1119)
Browse files Browse the repository at this point in the history
  • Loading branch information
thescientist13 authored Jun 29, 2023
1 parent 7c4aa01 commit 04c3eaf
Show file tree
Hide file tree
Showing 180 changed files with 651 additions and 653 deletions.
6 changes: 3 additions & 3 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ module.exports = {
'no-unused-expressions': 0,
'no-useless-call': 0,
'no-void': 0,
'no-warning-comments': [1, {
'no-warning-comments': [1, {
'terms': [
'todo',
' fixme',
Expand Down Expand Up @@ -142,7 +142,7 @@ module.exports = {
'comma-style': [2, 'last'],
'computed-property-spacing': 0,
'consistent-this': [0, 'self', 'that'],
'eol-last': 0,
'eol-last': [2, 'never'],
'func-names': 0,
'func-style': 0,
'id-length': 0,
Expand Down Expand Up @@ -172,7 +172,7 @@ module.exports = {
'no-new-object': 2,
'no-spaced-func': 2,
'no-ternary': 0,
'no-trailing-spaces': 0,
'no-trailing-spaces': 2,
'no-underscore-dangle': [2, { 'allowAfterThis': true }],
'no-unneeded-ternary': 2,
'object-curly-spacing': [2, 'always', {}],
Expand Down
10 changes: 5 additions & 5 deletions packages/cli/src/commands/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,17 @@ const runProductionBuild = async (compilation) => {
return plugin.type === 'server';
}).map((plugin) => {
const provider = plugin.provider(compilation);

if (!(provider instanceof ServerInterface)) {
console.warn(`WARNING: ${plugin.name}'s provider is not an instance of ServerInterface.`);
}

return provider;
})];

await Promise.all(servers.map(async (server) => {
await server.start();

return Promise.resolve(server);
}));

Expand All @@ -119,7 +119,7 @@ const runProductionBuild = async (compilation) => {
reject(err);
}
});

};

export { runProductionBuild };
4 changes: 2 additions & 2 deletions packages/cli/src/commands/develop.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ const runDevServer = async (compilation) => {

try {
const { port } = compilation.config.devServer;

(await getDevServer(compilation)).listen(port, () => {

console.info(`Started local development server at localhost:${port}`);

const servers = [...compilation.config.plugins.filter((plugin) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/eject.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ const ejectConfiguration = async (compilation) => {
try {
const configFileDirUrl = new URL('../config/', import.meta.url);
const configFiles = await fs.readdir(configFileDirUrl);

for (const file of configFiles) {
const from = new URL(`./${file}`, configFileDirUrl);
const to = new URL(`./${file}`, compilation.context.projectDirectory);

await fs.copyFile(from, to);

console.log(`Ejected ${file} successfully.`);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/config/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ const getRollupConfigForScriptResources = async (compilation) => {
return [{
preserveEntrySignatures: 'strict', // https://github.com/ProjectEvergreen/greenwood/pull/990
input,
output: {
output: {
dir: normalizePathnameForWindows(outputDir),
entryFileNames: '[name].[hash].js',
chunkFileNames: '[name].[hash].js',
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const run = async() => {
await (await import('./commands/eject.js')).ejectConfiguration(compilation);

break;
default:
default:
console.warn(`
Error: not able to detect command. try using the --help flag if
you're encountering issues running Greenwood. Visit our docs for more
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/lib/node-modules-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import fs from 'fs/promises';
// and return the root absolute location
async function getNodeModulesLocationForPackage(packageName) {
let nodeModulesUrl;

try {
const packageEntryLocation = (await import.meta.resolve(packageName)).replace(/\\/g, '/'); // force / for consistency and path matching

Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/lib/server-interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ class ServerInterface {
this.compilation = compilation;
this.options = options;
}

async start() {
return Promise.resolve(true);
}

async stop() {
return Promise.resolve(true);
}
Expand Down
16 changes: 8 additions & 8 deletions packages/cli/src/lib/walker-package-ranger.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ async function walkModule(modulePath, dependency) {
if (!importMap[sourceValue]) {
updateImportMap(sourceValue, `/node_modules/${sourceValue}`);
}

await walkPackageJson(path.join(absoluteNodeModulesLocation, 'package.json'));
} else if (isBarePath) {
updateImportMap(sourceValue, `/node_modules/${sourceValue}`);
Expand Down Expand Up @@ -128,18 +128,18 @@ async function walkPackageJson(packageJson = {}) {
if (Array.isArray(entry)) {
// we have an exportMap
const exportMap = entry;

for (const entry of exportMap) {
const exportMapEntry = dependencyPackageJson.exports[entry];
let packageExport;

if (Array.isArray(exportMapEntry)) {
let fallbackPath;
let esmPath;

exportMapEntry.forEach((mapItem) => {
switch (typeof mapItem) {

case 'string':
fallbackPath = mapItem;
break;
Expand All @@ -159,18 +159,18 @@ async function walkPackageJson(packageJson = {}) {
default:
console.warn(`Sorry, we were unable to detect the module type for ${mapItem} :(. please consider opening an issue to let us know about your use case.`);
break;

}
});

packageExport = esmPath
? esmPath
: fallbackPath;
} else if (exportMapEntry.import || exportMapEntry.default) {
packageExport = exportMapEntry.import
? exportMapEntry.import
: exportMapEntry.default;

// use the dependency itself as an entry in the importMap
if (entry === '.') {
updateImportMap(dependency, `/node_modules/${path.join(dependency, packageExport)}`);
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/lifecycles/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ async function bundleStyleResources(compilation, resourcePlugins) {
if (src) {
const basename = path.basename(srcPath);
const basenamePieces = path.basename(srcPath).split('.');
const fileNamePieces = srcPath.split('/').filter(piece => piece !== ''); // normalize by removing any leading /'s
const fileNamePieces = srcPath.split('/').filter(piece => piece !== ''); // normalize by removing any leading /'s

optimizedFileName = srcPath.indexOf('/node_modules') >= 0
? `${basenamePieces[0]}.${hashString(contents)}.css`
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/lifecycles/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const initContext = async({ config }) => {
recursive: true
});
}

resolve(context);
} catch (err) {
console.log(err);
Expand Down
12 changes: 6 additions & 6 deletions packages/cli/src/lifecycles/graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const generateGraph = async (compilation) => {
if (isDirectory) {
pages = await walkDirectoryForPages(filenameUrlAsDir, pages);
} else {
const extension = `.${filenameUrl.pathname.split('.').pop()}`;
const extension = `.${filenameUrl.pathname.split('.').pop()}`;
const isStatic = extension === '.md' || extension === '.html';
const isDynamic = extension === '.js';
const relativePagePath = filenameUrl.pathname.replace(pagesDir.pathname, '/');
Expand Down Expand Up @@ -69,7 +69,7 @@ const generateGraph = async (compilation) => {
if (isStatic) {
const fileContents = await fs.readFile(filenameUrl, 'utf8');
const { attributes } = fm(fileContents);

template = attributes.template || 'page';
title = attributes.title || title;
id = attributes.label || id;
Expand Down Expand Up @@ -120,7 +120,7 @@ const generateGraph = async (compilation) => {
let ssrFrontmatter;

filePath = route;

await new Promise((resolve, reject) => {
const worker = new Worker(routeWorkerUrl);

Expand All @@ -144,13 +144,13 @@ const generateGraph = async (compilation) => {
route
});
});

if (ssrFrontmatter) {
template = ssrFrontmatter.template || template;
title = ssrFrontmatter.title || title;
imports = ssrFrontmatter.imports || imports;
customData = ssrFrontmatter.data || customData;

/* Menu Query
* Custom front matter - Variable Definitions
* --------------------------------------------------
Expand All @@ -161,7 +161,7 @@ const generateGraph = async (compilation) => {
*/
customData.menu = ssrFrontmatter.menu || '';
customData.index = ssrFrontmatter.index || '';
}
}
} else {
console.debug(`Unhandled extension (.${extension}) for route => ${route}`);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/lifecycles/prerender.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ async function staticRenderCompilation(compilation) {
const plugins = getPluginInstances(compilation);

console.info('pages to generate', `\n ${pages.map(page => page.route).join('\n ')}`);

await Promise.all(pages.map(async (page) => {
const { route, outputPath } = page;
const outputDirUrl = new URL(`.${route}`, scratchDir);
Expand Down
8 changes: 4 additions & 4 deletions packages/cli/src/lifecycles/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ async function getDevServer(compilation) {
ctx.status = 500;
console.error(e);
}

await next();
});

Expand Down Expand Up @@ -159,7 +159,7 @@ async function getDevServer(compilation) {
ctx.status = ctx.status;
ctx.set('Content-Type', ctx.response.header['content-type']);
ctx.set('Etag', etagHash);

// TODO automatically loop and apply all custom headers to Koa response, include Content-Type below
// https://github.com/ProjectEvergreen/greenwood/issues/1048
if (response.headers.has('Content-Length')) {
Expand Down Expand Up @@ -280,7 +280,7 @@ async function getStaticServer(compilation, composable) {
await next();
}
});

return app;
}

Expand Down Expand Up @@ -326,7 +326,7 @@ async function getHybridServer(compilation) {
return app;
}

export {
export {
getDevServer,
getStaticServer,
getHybridServer
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async function getCustomLoaderResponse(url, body = '', checkOnly = false) {
for (const plugin of resourcePlugins) {
if (plugin.shouldServe && await plugin.shouldServe(url, request)) {
shouldHandle = true;

if (!checkOnly) {
response = await plugin.serve(url, request);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/plugins/resource/plugin-api-routes.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
*
*
* Manages routing to API routes.
*
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/plugins/resource/plugin-dev-proxy.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
*
*
* Manages routing devServer.proxy entries to their destination.
*
*/
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/plugins/resource/plugin-node-modules.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
*
*
* Detects and fully resolves requests to node_modules and handles creating an importMap.
*
*/
Expand Down Expand Up @@ -81,7 +81,7 @@ class NodeModulesResource extends ResourceInterface {
}

const userPackageJson = await getPackageJson(context);

// if there are dependencies and we haven't generated the importMap already
// walk the project's package.json for all its direct dependencies
// for each entry found in dependencies, find its entry point
Expand Down Expand Up @@ -118,7 +118,7 @@ const greenwoodPluginNodeModules = [{
replace({
// https://github.com/ProjectEvergreen/greenwood/issues/582
'preventAssignment': true,

// https://github.com/rollup/rollup/issues/487#issuecomment-177596512
'process.env.NODE_ENV': JSON.stringify('production')
}),
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/plugins/resource/plugin-source-maps.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
*
*
* Detects and fully resolve requests to source map (.map) files.
*
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/plugins/resource/plugin-standard-audio.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
*
*
* Manages web standard resource related operations for audio formats.
* This is a Greenwood default plugin.
*
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/plugins/resource/plugin-standard-font.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
*
*
* Manages web standard resource related operations for fonts.
* This is a Greenwood default plugin.
*
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/plugins/resource/plugin-standard-image.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
*
*
* Manages web standard resource related operations for image formats.
* This is a Greenwood default plugin.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
*
*
* Manages web standard resource related operations for JavaScript.
* This is a Greenwood default plugin.
*
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/plugins/resource/plugin-standard-json.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
*
*
* Manages web standard resource related operations for JSON.
* This is a Greenwood default plugin.
*
Expand Down
Loading

0 comments on commit 04c3eaf

Please sign in to comment.