New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor lib/rules/__tests__/*
test files to migrate to ESM
#7024
Conversation
This change is performed by the following script (though it requires a bit of manual). ```shell node to-esm.mjs lib/rules/*/__tests__/index.js ``` ```js // to-esm.mjs import { argv, stdout } from 'node:process'; import { readFile, unlink, writeFile } from 'node:fs/promises'; import { execSync } from 'node:child_process'; async function processFile(file) { const ruleFile = file.replace('/__tests__/index.js', '/index.js'); if ((await readFile(ruleFile, 'utf8')).includes('\tdeprecated: true,')) { stdout.write(`Skip deprecated ${file}\n`); return; } let lines = (await readFile(file, 'utf8')).split('\n'); lines = lines.filter((line) => !line.includes('use strict')); lines.forEach((line, i) => { line = line.replace( "const stripIndent = require('common-tags').stripIndent", "const { stripIndent } = require('common-tags')", ); line = line.replace( "const { messages, ruleName } = require('..');", "import rule from '../index.js'; const { messages, ruleName } = rule;", ); line = line.replace(/const (.+) = require\('(\..+)'\)/, 'import $1 from "$2.js"'); line = line.replace(/const (.+) = require\('(.+)'\)/, 'import $1 from "$2"'); lines[i] = line; }); const newFile = file.replace(/\.js$/, '.mjs'); const newContent = `${lines.join('\n')}\n`; await writeFile(newFile, newContent); stdout.write(`=> ${newFile}\n`); await unlink(file); } const files = argv.slice(2); Promise.all(files.map((f) => processFile(f))).then(() => { execSync(`npx prettier --loglevel silent --write lib/rules`, { encoding: 'utf8' }); }); ```
|
I'm investigating the Out of Memory error on CI (coverage):
https://github.com/stylelint/stylelint/actions/runs/5433854986/jobs/9885027327#step:6:255 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes on main
and filtering the deprecated rules out LGTM.
Thank you!
Ref #5291
This change is performed by the following script (though it requires a bit of manual).
node to-esm.mjs lib/rules/*/__tests__/index.js
Note that this change does NOT include deprecated rules which were removed on the
v16
branch.