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
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ module.exports = {
{
files: ['**/*.ts', '**/*.tsx'],
rules: {
'rulesdir/no-any-except-union-method-signature': 'error'
'rulesdir/no-any-except-union-method-signature': 'error',
'rulesdir/no-pr-in-user-strings': 'error'
}
}
]
Expand Down
1 change: 1 addition & 0 deletions build/eslint-rules/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
module.exports = {
'public-methods-well-defined-types': require('./public-methods-well-defined-types'),
'no-any-except-union-method-signature': require('./no-any-except-union-method-signature'),
'no-pr-in-user-strings': require('./no-pr-in-user-strings'),
};
96 changes: 96 additions & 0 deletions build/eslint-rules/no-pr-in-user-strings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

'use strict';

/**
* ESLint rule to detect the string "PR" in user-facing strings and suggest using "pull request" instead.
* This rule checks:
* - String literals passed to vscode.l10n.t() calls
* - String literals passed to l10n.t() calls
*/

module.exports = {
meta: {
type: 'problem',
docs: {
description: 'Detect "PR" in user-facing strings and suggest using "pull request" instead',
category: 'Best Practices',
recommended: true,
},
schema: [],
messages: {
noPrInUserString: 'Use "pull request" instead of "PR" in user-facing strings. Found: {{foundText}}',
},
},

create(context) {
/**
* Check if a string contains "PR" as a standalone word
*/
function containsPR(str) {
// Use word boundary regex to match "PR" as a standalone word
const prRegex = /\bPR\b/;
return prRegex.test(str);
}

/**
* Check if a node is a call to vscode.l10n.t or l10n.t
*/
function isL10nTCall(node) {
if (node.type !== 'CallExpression') {
return false;
}

const callee = node.callee;

// Handle l10n.t() calls
if (callee.type === 'MemberExpression' &&
callee.property &&
callee.property.name === 't') {

// Check for vscode.l10n.t
if (callee.object.type === 'MemberExpression' &&
callee.object.object &&
callee.object.object.name === 'vscode' &&
callee.object.property &&
callee.object.property.name === 'l10n') {
return true;
}

// Check for l10n.t
if (callee.object.type === 'Identifier' &&
callee.object.name === 'l10n') {
return true;
}
}

return false;
}

return {
// Check CallExpression nodes for l10n.t calls
CallExpression(node) {
if (isL10nTCall(node)) {
// Check the first argument (string literal)
if (node.arguments && node.arguments.length > 0) {
const firstArg = node.arguments[0];
if (firstArg.type === 'Literal' && typeof firstArg.value === 'string') {
if (containsPR(firstArg.value)) {
context.report({
node: firstArg,
messageId: 'noPrInUserString',
data: {
foundText: firstArg.value
}
});
}
}
}
}
}
};
}
};
2 changes: 1 addition & 1 deletion src/issues/issueFeatureRegistrar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ export class IssueFeatureRegistrar extends Disposable {
} else {
const pullRequestModel = issue.pullRequestModel;
const remote = pullRequestModel.githubRepository.remote;
commands.executeCommand(chatCommandID, vscode.l10n.t('@githubpr Summarize PR {0}/{1}#{2}', remote.owner, remote.repositoryName, pullRequestModel.number));
commands.executeCommand(chatCommandID, vscode.l10n.t('@githubpr Summarize pull request {0}/{1}#{2}', remote.owner, remote.repositoryName, pullRequestModel.number));
}
}),
);
Expand Down