Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 49 additions & 49 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"homepage": "https://github.com/e18e/cli#readme",
"dependencies": {
"@clack/prompts": "^1.7.0",
"@e18e/web-features-codemods": "^0.2.1",
"@e18e/web-features-codemods": "^0.3.0",
"@publint/pack": "^0.1.5",
"core-js-compat": "^3.48.0",
"enginematch": "^0.2.0",
Expand All @@ -56,7 +56,7 @@
"gunshi": "^0.35.1",
"lockparse": "^0.5.2",
"module-replacements": "^3.0.0",
"module-replacements-codemods": "^2.0.0",
"module-replacements-codemods": "^2.0.1",
"obug": "^2.1.3",
"package-manager-detector": "^1.7.0",
"publint": "^0.3.21",
Expand Down
21 changes: 9 additions & 12 deletions src/analyze/web-features-codemods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,22 @@ export async function runWebFeaturesCodemodsAnalysis(
continue;
}

const matches: string[] = [];
for (const [name, codemod] of webFeatureCodemods) {
try {
if (codemod.test({source})) {
matches.push(name);
const testResult = codemod.test({source});
if (testResult.hasMatch) {
messages.push({
severity: 'suggestion',
score: 0,
file: filePath,
message: `Consider using the ${name} feature here.`,
range: testResult.range
});
}
} catch {
continue;
}
}

if (matches.length > 0) {
messages.push({
severity: 'suggestion',
score: 0,
file: filePath,
message: `Can use newer web features: ${matches.join(', ')}.`
});
}
}

return {messages};
Expand Down
16 changes: 10 additions & 6 deletions src/commands/analyze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,15 +211,16 @@ export async function run(ctx: CommandContext<typeof meta>) {

const formatBulletMessage = (
text: string,
label: (typeof labels)[keyof typeof labels]
label: (typeof labels)[keyof typeof labels],
location = ''
) => {
const severity = styleText(label.color, label.text.padEnd(labelWidth));
const indent = ' '.repeat(gutter);
const locationCol = location ? `${styleText('dim', location)} ` : '';
const prefix = ` ${locationCol}${severity} `;
const indent = ' '.repeat(gutter + (location ? location.length + 2 : 0));
return wrapAnsi(text, maxContentWidth)
.split('\n')
.map((line, i) =>
i === 0 ? ` ${severity} ${line}` : `${indent}${line}`
)
.map((line, i) => (i === 0 ? `${prefix}${line}` : `${indent}${line}`))
.join('\n');
};

Expand Down Expand Up @@ -256,8 +257,11 @@ export async function run(ctx: CommandContext<typeof meta>) {
spacing: 0
});
for (const msg of group) {
const location = msg.range
? `${msg.range.start.line + 1}:${msg.range.start.column + 1}`
: '';
prompts.log.message(
formatBulletMessage(msg.message, labels[msg.severity]),
formatBulletMessage(msg.message, labels[msg.severity], location),
{spacing: 0}
);
}
Expand Down
64 changes: 60 additions & 4 deletions src/test/analyze/__snapshots__/web-features-codemods.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,33 @@ exports[`runWebFeaturesCodemodsAnalysis > handles a file with multiple matches 1
[
{
"file": "index.js",
"message": "Can use newer web features: arrayAt, exponentiation.",
"message": "Consider using the arrayAt feature here.",
"range": {
"end": {
"column": 36,
"line": 0,
},
"start": {
"column": 13,
"line": 0,
},
},
"score": 0,
"severity": "suggestion",
},
{
"file": "index.js",
"message": "Consider using the exponentiation feature here.",
"range": {
"end": {
"column": 34,
"line": 1,
},
"start": {
"column": 16,
"line": 1,
},
},
"score": 0,
"severity": "suggestion",
},
Expand All @@ -17,7 +43,17 @@ exports[`runWebFeaturesCodemodsAnalysis > handles a file with one match 1`] = `
[
{
"file": "index.js",
"message": "Can use newer web features: arrayAt.",
"message": "Consider using the arrayAt feature here.",
"range": {
"end": {
"column": 36,
"line": 0,
},
"start": {
"column": 13,
"line": 0,
},
},
"score": 0,
"severity": "suggestion",
},
Expand All @@ -28,7 +64,17 @@ exports[`runWebFeaturesCodemodsAnalysis > handles multiple occurrences of the sa
[
{
"file": "index.js",
"message": "Can use newer web features: arrayAt.",
"message": "Consider using the arrayAt feature here.",
"range": {
"end": {
"column": 40,
"line": 0,
},
"start": {
"column": 17,
"line": 0,
},
},
"score": 0,
"severity": "suggestion",
},
Expand All @@ -41,7 +87,17 @@ exports[`runWebFeaturesCodemodsAnalysis > respects the src option 1`] = `
[
{
"file": "src/index.js",
"message": "Can use newer web features: arrayAt.",
"message": "Consider using the arrayAt feature here.",
"range": {
"end": {
"column": 36,
"line": 0,
},
"start": {
"column": 13,
"line": 0,
},
},
"score": 0,
"severity": "suggestion",
},
Expand Down
Loading
Loading