Skip to content

Commit

Permalink
add lint rules for console.log and fix postcss-browser-comments (#1482
Browse files Browse the repository at this point in the history
)
  • Loading branch information
romainmenke authored Sep 25, 2024
1 parent 143aa15 commit 9ff9af4
Show file tree
Hide file tree
Showing 55 changed files with 190 additions and 88 deletions.
3 changes: 3 additions & 0 deletions .github/bin/detect-executable-files/to-github-annotations.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ if (!fileNames || !fileNames.length) {
}

if (!process.env.GITHUB_ACTIONS) {
// eslint-disable-next-line no-console
console.log('Unexpected executables:');
fileNames.forEach((f) => {
// eslint-disable-next-line no-console
console.log(`chmod a-x ${f}`);
});
process.exit(1);
Expand All @@ -51,6 +53,7 @@ fileNames.forEach((f) => {
},
);

// eslint-disable-next-line no-console
console.log(annotation);
});

Expand Down
1 change: 1 addition & 0 deletions .github/bin/format-package-json.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ const formatted = {};
Object.assign(formatted, packageJSONInfo);

if (process.env.GITHUB_ACTIONS && JSON.stringify(formatted, null, '\t') !== packageJSONInfoCopy) {
// eslint-disable-next-line no-console
console.error(`::error file=${path.relative(process.env.GITHUB_WORKSPACE, path.resolve('./package.json'))},line=1,col=1::package.json has an incorrect field order. Run "npm run lint" to resolve.`);
process.exit(1);
}
Expand Down
1 change: 1 addition & 0 deletions .github/bin/license/check-license.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ const allFiles = (await getFiles('./')).filter((file) => {
}

if (logEntries.length > 0) {
// eslint-disable-next-line no-console
console.log(logEntries.join('\n'));
process.exit(1);
}
3 changes: 2 additions & 1 deletion .github/bin/list-workspaces/list-workspaces.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ export async function listWorkspaces() {
});

return result;
} catch(err) {
} catch (err) {
// eslint-disable-next-line no-console
console.error(err);
throw new Error('failed to get the list of workspaces');
}
Expand Down
2 changes: 2 additions & 0 deletions .github/bin/modified-workspaces/modified-workspaces.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export async function listModifiedWorkspaces() {

for (const internalDependency of internalDependencies) {
if (modifiedFile.startsWith(internalDependency)) {
// eslint-disable-next-line no-console
console.error('modified a private dependency', modifiedFile);
// this file can influence anything
// anything or everything might have changed
Expand All @@ -82,6 +83,7 @@ export async function listModifiedWorkspaces() {
}

if (isNonWorkspaceFile) {
// eslint-disable-next-line no-console
console.error('modifiedFile outside of workspaces', modifiedFile);
// files outside of workspaces include "package-lock.json", rollup config, ...
// anything or everything might have changed
Expand Down
25 changes: 17 additions & 8 deletions .github/bin/new-plugin.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@ const pluginName = process.argv.slice(2).join(' ');
// Plugin name checks
{
if (!pluginName) {
// eslint-disable-next-line no-console
console.warn('A plugin name must be provided:\n new-plugin <human readable name>\n new-plugin Cascade Layers');
process.exit(1);
}

if (pluginName.startsWith('postcss-')) {
// eslint-disable-next-line no-console
console.warn('Plugin name cannot start with "postcss-", it is added by this scripts.');
process.exit(1);
}

if (pluginName.includes('/')) {
// eslint-disable-next-line no-console
console.warn('Plugin name cannot contain "/"');
process.exit(1);
}
Expand All @@ -29,13 +32,15 @@ const exportName = 'postcss' + pluginName.replace(/\s+/g, '');
const basePluginDir = './plugins/postcss-base-plugin';
const pluginDir = './plugins/' + pluginSlug;

// eslint-disable-next-line no-console
console.log(`- Creating new plugin ${pluginName}`);

// Copy base plugin
{
await fs.rm(pluginDir, { recursive: true, force: true });
await fs.cp(basePluginDir, pluginDir, { recursive: true });

// eslint-disable-next-line no-console
console.log('- Copied base plugin to', pluginDir);
}

Expand All @@ -44,6 +49,7 @@ console.log(`- Creating new plugin ${pluginName}`);
await fs.rm(path.join(pluginDir, 'dist'), { recursive: true, force: true });
await fs.rm(path.join(pluginDir, 'node_modules'), { recursive: true, force: true });

// eslint-disable-next-line no-console
console.log('- Cleaned up files and directories not required in a new plugin');
}

Expand All @@ -65,6 +71,7 @@ console.log(`- Creating new plugin ${pluginName}`);
`,
);

// eslint-disable-next-line no-console
console.log('- Relabeled references to base plugin');
}

Expand All @@ -85,21 +92,23 @@ console.log(`- Creating new plugin ${pluginName}`);

await fs.writeFile(path.join(pluginDir, 'package.json'), JSON.stringify(packageInfo, null, '\t'));

// eslint-disable-next-line no-console
console.log('- Updated "package.json"');
}

// eslint-disable-next-line no-console
console.log('\nDone! 🎉');

// Next steps
{
console.log('\nYour next steps:');
console.log('- Run : "npm install" from the root directory');
console.log(`- Run : "cd plugins/${pluginSlug}"`);
console.log('- Run : "npm run docs" to generate documentation');
console.log('- Run : "npm run build" to build your plugin');
console.log('- Run : "npm run test" to test your plugin');
console.log('- Run : "npm run test:rewrite-expects" to update test expects');
console.log('\nChange "blue" to "purple" in "src/index.ts" and see how it affects the test outcome');
console.log('\nYour next steps:'); // eslint-disable-line no-console
console.log('- Run : "npm install" from the root directory'); // eslint-disable-line no-console
console.log(`- Run : "cd plugins/${pluginSlug}"`); // eslint-disable-line no-console
console.log('- Run : "npm run docs" to generate documentation'); // eslint-disable-line no-console
console.log('- Run : "npm run build" to build your plugin'); // eslint-disable-line no-console
console.log('- Run : "npm run test" to test your plugin'); // eslint-disable-line no-console
console.log('- Run : "npm run test:rewrite-expects" to update test expects'); // eslint-disable-line no-console
console.log('\nChange "blue" to "purple" in "src/index.ts" and see how it affects the test outcome'); // eslint-disable-line no-console
}

// Helpers
Expand Down
4 changes: 4 additions & 0 deletions .github/bin/release-plan/add-to-changelog.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ export function addUpdatedPackagesToChangelog(workspace, changelog, changeLogAdd
// Find the heading for the unreleased changes.
const unreleasedSectionStart = changelog.indexOf('Unreleased');
if (unreleasedSectionStart === -1) {
// eslint-disable-next-line no-console
console.log('Unable to update the Changelog for ' + workspace.name);
return changelog;
}

// Find the start of the section content for the unreleased changes.
const unreleasedSectionContent = changelog.indexOf('\n', unreleasedSectionStart) + 1;
if (unreleasedSectionContent === 0) {
// eslint-disable-next-line no-console
console.log('Unable to update the Changelog for ' + workspace.name);
return changelog;
}
Expand All @@ -23,13 +25,15 @@ export function addUpdatedPackagesToChangelog(workspace, changelog, changeLogAdd
// Search backward from the next section to find the line for the last unreleased change.
const listEnd = changelog.lastIndexOf('- ', nextSectionStart);
if (listEnd < unreleasedSectionContent) {
// eslint-disable-next-line no-console
console.log('Unable to update the Changelog for ' + workspace.name);
return changelog;
}

// Get the start of the next line after the last change.
const nextLine = changelog.indexOf('\n', listEnd) + 1;
if (nextLine === 0) {
// eslint-disable-next-line no-console
console.log('Unable to update the Changelog for ' + workspace.name);
return changelog;
}
Expand Down
3 changes: 3 additions & 0 deletions .github/bin/release-plan/discord-announce.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,19 @@ export async function discordAnnounceDryRun() {

const discordArgument = process.argv.slice(2).find(arg => arg.includes('--discord='));
if (!discordArgument) {
// eslint-disable-next-line no-console
console.log('Discord announce webhook URL: not set');
return;
}

const [, webHookUrl] = discordArgument.split('=');

if (!webHookUrl) {
// eslint-disable-next-line no-console
console.log('Discord announce webhook URL: not set');
return;
}

// eslint-disable-next-line no-console
console.log(`Discord announce webhook URL: ${webHookUrl}`);
}
9 changes: 9 additions & 0 deletions .github/bin/release-plan/prepare-current-release-plan.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export async function prepareCurrentReleasePlan() {
} else if (changelog.includes('Unreleased (major)')) {
increment = 'major';
} else {
// eslint-disable-next-line no-console
console.warn('Invalid CHANGELOG.md in', workspace.name);
notReleasableNow.set(workspace.name, workspace);
continue WORKSPACES_LOOP;
Expand All @@ -61,6 +62,7 @@ export async function prepareCurrentReleasePlan() {
notReleasableNow.set(workspace.name, workspace);
}

// eslint-disable-next-line no-console
console.warn('Current npm user does not have write access for', workspace.name);
continue WORKSPACES_LOOP;
}
Expand Down Expand Up @@ -92,23 +94,30 @@ export async function prepareCurrentReleasePlan() {
}

if (needsRelease.size === 0) {
// eslint-disable-next-line no-console
console.log('Nothing to release');
process.exit(0);
}

if (maybeNextPlan.size) {
// eslint-disable-next-line no-console
console.log('Excluded:');
for (const workspace of maybeNextPlan.values()) {
// eslint-disable-next-line no-console
console.log(` - ${workspace.name}`);
}
// eslint-disable-next-line no-console
console.log(''); // empty line
}

if (needsRelease.size) {
// eslint-disable-next-line no-console
console.log('Release plan:');
for (const workspace of needsRelease.values()) {
// eslint-disable-next-line no-console
console.log(` - ${workspace.name} (${workspace.increment})`);
}
// eslint-disable-next-line no-console
console.log(''); // empty line
}

Expand Down
1 change: 1 addition & 0 deletions .github/bin/release-plan/prepare-next-release-plan.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export async function prepareNextReleasePlan(needsRelease, notReleasableNow) {
// Downstream dependents
let didChangeDownstreamPackages = false;

// eslint-disable-next-line no-console
console.log('\nPreparing next plan');

for (const workspace of notReleasableNow.values()) {
Expand Down
6 changes: 6 additions & 0 deletions .github/bin/release-plan/release-plan.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ if (process.argv.slice(2).includes('--dry-run')) {
}

for (const workspace of needsRelease.values()) {
// eslint-disable-next-line no-console
console.log(`Releasing : ${workspace.name}`);
// Increment the version
workspace.newVersion = await npmVersion(workspace.increment, workspace.path);
Expand Down Expand Up @@ -86,21 +87,26 @@ for (const workspace of needsRelease.values()) {

const didChangeDownstreamPackages = await prepareNextReleasePlan(needsRelease, notReleasableNow);

// eslint-disable-next-line no-console
console.log('\nUpdating lock file');
await npmInstall();

if (didChangeDownstreamPackages) {
await commitAfterDependencyUpdates();
}

// eslint-disable-next-line no-console
console.log('\nDone 🎉');

if (didChangeDownstreamPackages || maybeNextPlan.size > 0) {
// eslint-disable-next-line no-console
console.log('\nNotes:'); // empty line
if (didChangeDownstreamPackages) {
// eslint-disable-next-line no-console
console.log(' - updated "package.json" files of downstream packages.');
}
if (maybeNextPlan.size) {
// eslint-disable-next-line no-console
console.log(' - some packages were excluded from this plan. A next plan of releases might be available now.');
}
}
2 changes: 2 additions & 0 deletions .github/bin/release-plan/run-and-print-debug-on-fail.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ export async function runAndPrintDebugOnFail(runningJob, prelude, helpMessage) {
try {
await runningJob;
} catch (e) {
// eslint-disable-next-line no-console
console.error(e);

// eslint-disable-next-line no-console
console.log(`-----------\n\n${prelude.trim()}\n\n${helpMessage.trim()}`);

process.exit(1);
Expand Down
1 change: 1 addition & 0 deletions cli/csstools-cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ async function main(): Promise<void> {
' @csstools/csstools-cli postcss-preset-env',
];

// eslint-disable-next-line no-console
console.warn(allHelp.join('\n'));
}
}
Expand Down
3 changes: 3 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export default [
},

rules: {
'no-console': ['error'],
quotes: ['error', 'single'],
'comma-dangle': ['error', 'always-multiline'],
semi: ['error', 'always'],
Expand Down Expand Up @@ -75,6 +76,7 @@ export default [
},

rules: {
'no-console': ['error'],
'no-unused-vars': ['error', { 'caughtErrorsIgnorePattern': '_' }],
'no-constant-condition': 'off',
},
Expand All @@ -93,6 +95,7 @@ export default [
},
},
rules: {
'no-console': ['error'],
'no-shadow': 'off',
'@typescript-eslint/no-shadow': 'error',

Expand Down
2 changes: 1 addition & 1 deletion experimental/css-has-pseudo/dist/browser-global.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion experimental/css-has-pseudo/dist/browser.cjs.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion experimental/css-has-pseudo/dist/browser.mjs.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions experimental/css-has-pseudo/src/browser.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export default function cssHasPseudo() {
// eslint-disable-next-line no-console
console.log('"@csstools/css-has-pseudo-experimental" is no longer supported. Please use "css-has-pseudo" instead.');
}
8 changes: 4 additions & 4 deletions packages/base-cli/src/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export function parseArguments(args: Array<string>, allowedPluginOpts: Array<str
default:
if (arg.indexOf('-') === 0) {
// Stryker disable next-line all
console.warn(`[error] unknown argument : ${arg}\n`);
console.warn(`[error] unknown argument : ${arg}\n`); // eslint-disable-line no-console
// Stryker disable next-line all
helpLogger();
return SignalValue.InvalidArguments;
Expand Down Expand Up @@ -123,7 +123,7 @@ export function parseArguments(args: Array<string>, allowedPluginOpts: Array<str

if (parsedArgs.inputs.length > 1 && parsedArgs.output) {
// Stryker disable next-line all
console.warn('[error] omit "--output" when processing multiple inputs\n');
console.warn('[error] omit "--output" when processing multiple inputs\n'); // eslint-disable-line no-console
// Stryker disable next-line all
helpLogger();
return SignalValue.InvalidArguments;
Expand All @@ -148,7 +148,7 @@ export function parseArguments(args: Array<string>, allowedPluginOpts: Array<str
parsedPluginOpts = JSON.parse(pluginOpts) as Record<string, unknown>;
} catch {
// Stryker disable next-line all
console.warn('[error] plugin options must be valid JSON\n');
console.warn('[error] plugin options must be valid JSON\n'); // eslint-disable-line no-console
// Stryker disable next-line all
helpLogger();
return SignalValue.InvalidArguments;
Expand All @@ -161,7 +161,7 @@ export function parseArguments(args: Array<string>, allowedPluginOpts: Array<str
parsedArgs.pluginOptions[key] = value;
} else {
// Stryker disable next-line all
console.warn(`[error] unknown plugin option: ${key}\n`);
console.warn(`[error] unknown plugin option: ${key}\n`); // eslint-disable-line no-console
// Stryker disable next-line all
helpLogger();
return SignalValue.InvalidArguments;
Expand Down
1 change: 1 addition & 0 deletions packages/base-cli/src/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export function helpTextLogger(command: string, name: string, description: strin
}

return (): void => {
// eslint-disable-next-line no-console
console.warn(allHelp.join('\n'));
};
}
Loading

0 comments on commit 9ff9af4

Please sign in to comment.