Skip to content

Commit eafb06d

Browse files
authored
Merge branch 'develop' into find-last-index
Signed-off-by: Aayush Khanna <[email protected]>
2 parents 9c422d9 + d24969e commit eafb06d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+3158
-357
lines changed

.github/workflows/generate_pr_commit_message.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,21 @@ jobs:
7070
id: commit_message
7171
run: |
7272
COMMIT_MESSAGE=$($GITHUB_WORKSPACE/.github/workflows/scripts/generate_pr_commit_message $PR_NUMBER)
73+
EXIT_CODE=$?
74+
7375
echo "commit_message<<EOF" >> $GITHUB_OUTPUT
7476
echo "$COMMIT_MESSAGE" >> $GITHUB_OUTPUT
7577
echo "EOF" >> $GITHUB_OUTPUT
7678
79+
if [ $EXIT_CODE -eq 200 ]; then
80+
echo "has_tracking_issue=true" >> $GITHUB_OUTPUT
81+
else
82+
echo "has_tracking_issue=false" >> $GITHUB_OUTPUT
83+
fi
84+
85+
# Ensure the script itself doesn't fail the workflow:
86+
exit 0
87+
7788
# Post commit message as PR comment:
7889
- name: 'Post commit message as PR comment'
7990
uses: peter-evans/create-or-update-comment@v4
@@ -88,3 +99,5 @@ jobs:
8899
```
89100
90101
*Please review the above commit message and make any necessary adjustments.*
102+
103+
${{ steps.commit_message.outputs.has_tracking_issue == 'true' && '⚠️ **Action Required**: This PR references tracking issues. Please update the PR description to replace any "Closes", "Fixes", or "Resolves" keywords with "Ref" when referencing these issues.' || '' }}

.github/workflows/scripts/generate_pr_commit_message

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ GITHUB_API_URL="https://api.github.com"
4545
REPO_OWNER="stdlib-js"
4646
REPO_NAME="stdlib"
4747

48+
# Exit codes
49+
SUCCESS=0
50+
ERROR=1
51+
TRACKING_ISSUE_FOUND=200
52+
4853

4954
# FUNCTIONS #
5055

@@ -126,12 +131,12 @@ github_api() {
126131
else
127132
# Handle cases where POST data is required but not provided:
128133
echo "POST request requires data."
129-
on_error 1
134+
on_error $ERROR
130135
fi
131136
;;
132137
*)
133138
echo "Invalid HTTP method: $method"
134-
on_error 1
139+
on_error $ERROR
135140
;;
136141
esac
137142
}
@@ -226,8 +231,17 @@ main() {
226231
# Create a regex pattern from the keywords:
227232
keywords_pattern=$(IFS='|'; echo "${closing_keywords[*]}")
228233

234+
EXIT_CODE=$SUCCESS
229235
for issue in $issue_numbers; do
230-
if echo "$pr_body" | grep -Eiq "(${keywords_pattern})([[:space:]]+|:)[[:space:]]*#${issue}\b"; then
236+
# Fetch issue labels:
237+
issue_details=$(github_api "GET" "/repos/$REPO_OWNER/$REPO_NAME/issues/$issue")
238+
issue_labels=$(echo "$issue_details" | jq -r '.labels[].name')
239+
240+
# Check if the issue is a tracking issue:
241+
if echo "$issue_labels" | grep -q "Tracking Issue"; then
242+
EXIT_CODE=$TRACKING_ISSUE_FOUND
243+
ref_issues+="Ref: https://github.com/$REPO_OWNER/$REPO_NAME/issues/$issue\n"
244+
elif echo "$pr_body" | grep -Eiq "(${keywords_pattern})([[:space:]]+|:)[[:space:]]*#${issue}\b"; then
231245
closes_issues+="Closes: https://github.com/$REPO_OWNER/$REPO_NAME/issues/$issue\n"
232246
else
233247
ref_issues+="Ref: https://github.com/$REPO_OWNER/$REPO_NAME/issues/$issue\n"
@@ -265,6 +279,9 @@ main() {
265279

266280
# Output the commit message:
267281
echo -e "$commit_message"
282+
283+
# Return successful exit code (200 if a tracking issue was found, 0 otherwise):
284+
return $EXIT_CODE
268285
}
269286

270287
# Call main with all command-line arguments:

lib/node_modules/@stdlib/_tools/eslint/rules/vars-order/lib/main.js

Lines changed: 75 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,19 +81,88 @@ function main( context ) {
8181
break;
8282
}
8383

84+
/**
85+
* Sorts the variable declarations by name length.
86+
*
87+
* @private
88+
* @param {Object} a - input object
89+
* @param {Object} b - comparison object
90+
* @returns {number} number indicating sort order
91+
*/
92+
function sortVars( a, b ) {
93+
if ( fun( a.name.length, b.name.length ) ) {
94+
return 1;
95+
}
96+
return -1;
97+
}
98+
8499
/**
85100
* Reports the error message.
86101
*
87102
* @private
88103
* @param {string} msg - error message
89-
* @param {Object} loc - lines of code (object with `start` and `end` properties)
104+
* @param {ASTNode} node - node to fix
90105
*/
91-
function report( msg, loc ) {
106+
function report( msg, node ) {
92107
context.report({
93108
'node': null,
94109
'message': msg,
95-
'loc': loc
110+
'loc': node.loc,
111+
'fix': fix
96112
});
113+
114+
/**
115+
* Fixes the lint error by reordering the variable declarations inside of the function.
116+
*
117+
* @private
118+
* @param {Function} fixer - ESLint fixer
119+
* @returns {(Object|null)} fix or null
120+
*/
121+
function fix( fixer ) {
122+
var replacingText;
123+
var declarations;
124+
var startRange;
125+
var endRange;
126+
var source;
127+
var elem;
128+
var body;
129+
var i;
130+
var j;
131+
132+
declarations = [];
133+
replacingText = '';
134+
body = node.body.body;
135+
source = context.getSourceCode();
136+
137+
for ( i = 0; i < body.length; i++ ) {
138+
elem = body[ i ];
139+
if ( elem.type === 'VariableDeclaration' && elem.kind === 'var' ) {
140+
declarations.push({
141+
'text': source.getText( elem ),
142+
'name': elem.declarations[ 0 ].id.name,
143+
'col': elem.loc.start.column
144+
});
145+
if ( declarations.length === 1 ) {
146+
startRange = elem.range[ 0 ] - elem.loc.start.column;
147+
}
148+
endRange = elem.range[ 1 ];
149+
}
150+
}
151+
152+
declarations.sort( sortVars );
153+
154+
for ( i = 0; i < declarations.length; i++ ) {
155+
for ( j = 0; j < declarations[ i ].col; j++ ) {
156+
replacingText += '\t';
157+
}
158+
replacingText += declarations[ i ].text;
159+
if ( i !== declarations.length -1 ) {
160+
replacingText += '\n';
161+
}
162+
}
163+
164+
return fixer.replaceTextRange( [ startRange, endRange ], replacingText ); // eslint-disable-line max-len
165+
}
97166
}
98167

99168
/**
@@ -117,7 +186,7 @@ function main( context ) {
117186
if ( elem.type === 'VariableDeclaration' && elem.kind === 'var' ) {
118187
name = elem.declarations[ 0 ].id.name;
119188
if ( prevLength && !fun( name.length, prevLength ) ) {
120-
return report( 'Variable declarations inside of function are not ordered by length (in '+ order +' order)', node.loc );
189+
return report( 'Variable declarations inside of function are not ordered by length (in '+ order +' order)', node );
121190
}
122191
prevLength = name.length;
123192
}
@@ -135,9 +204,11 @@ function main( context ) {
135204

136205
rule = {
137206
'meta': {
207+
'type': 'layout',
138208
'docs': {
139209
'description': 'require variable declarations inside of functions to be ordered by length'
140210
},
211+
'fixable': 'code',
141212
'schema': [
142213
{
143214
'order': [ 'increasing', 'decreasing' ]

0 commit comments

Comments
 (0)