Skip to content

Commit

Permalink
chore: Upgrade linting (#178)
Browse files Browse the repository at this point in the history
* chore: Upgrade ESLint

* chore: Autofix new lint reports from upgrade

* chore: Fix new require-unicode-regexp errors

* chore: Fix JSDoc destructured param annotations

* chore: Remove extra JSDoc param annotation

* fix: default-param-last violation

I verified that the only call site in
`src/plugins/commit-message/index.js` line 144 provides all three
positional arguments. Since this is a private function, removing these
defaults can be done in a semver-patch change.
  • Loading branch information
btmills committed Jul 19, 2022
1 parent 79e82ee commit 085a46a
Show file tree
Hide file tree
Showing 28 changed files with 2,156 additions and 2,538 deletions.
4,318 changes: 1,959 additions & 2,359 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions package.json
Expand Up @@ -29,11 +29,11 @@
"probot-scheduler": "^1.0.3"
},
"devDependencies": {
"eslint": "^5.9.0",
"eslint-config-eslint": "^5.0.1",
"eslint-plugin-node": "^8.0.0",
"eslint": "^8.19.0",
"eslint-config-eslint": "^7.0.0",
"eslint-plugin-node": "^11.1.0",
"jest": "^26.1.0",
"lint-staged": "^11.1.2",
"lint-staged": "^12.5.0",
"nock": "^10.0.2",
"yorkie": "^2.0.0"
},
Expand Down
15 changes: 9 additions & 6 deletions src/plugins/auto-closer/index.js
Expand Up @@ -32,8 +32,9 @@ async function hasAutoCloseLabel(context) {
* Creates a search query to look for issues in a given repo that have been
* labeled "accepted", don't have an assignee/project/milestone, have been opened
* for 90 days and have been inactive for 30 days.
* @param {string} options.owner The owner of the repo where issues should be searched
* @param {string} options.repo The name of the repo where issues should be searched
* @param {Object} options Repository where issues should be searched
* @param {string} options.owner The owner of the repository
* @param {string} options.repo The name of the repository
* @returns {string} A search query to send to the GitHub API
*/
function createAutoCloseAcceptedSearchQuery({ owner, repo }) {
Expand All @@ -53,8 +54,9 @@ function createAutoCloseAcceptedSearchQuery({ owner, repo }) {
* Creates a search query to look for issues in a given repo that have not been
* labeled "accepted", don't have an assignee/project/milestone, have been
* inactive for 30 days.
* @param {string} options.owner The owner of the repo where issues should be searched
* @param {string} options.repo The name of the repo where issues should be searched
* @param {Object} options Repository where issues should be searched
* @param {string} options.owner The owner of the repository
* @param {string} options.repo The name of the repository
* @returns {string} A search query to send to the GitHub API
*/
function createAutoCloseUnacceptedSearchQuery({ owner, repo }) {
Expand All @@ -73,8 +75,9 @@ function createAutoCloseUnacceptedSearchQuery({ owner, repo }) {
* Creates a search query to look for issues in a given repo that have not been
* labeled "accepted", don't have an assignee/project/milestone, have been
* inactive for 30 days, and are labeled "question".
* @param {string} options.owner The owner of the repo where issues should be searched
* @param {string} options.repo The name of the repo where issues should be searched
* @param {Object} options Repository where issues should be searched
* @param {string} options.owner The owner of the repository
* @param {string} options.repo The name of the repository
* @returns {string} A search query to send to the GitHub API
*/
function createAutoCloseQuestionSearchQuery({ owner, repo }) {
Expand Down
12 changes: 6 additions & 6 deletions src/plugins/check-unit-test/index.js
Expand Up @@ -8,19 +8,19 @@

const path = require("path");

const TAG_REGEX = /^(?:Build|Chore|Docs|Upgrade):/;
const TAG_REGEX = /^(?:Build|Chore|Docs|Upgrade):/u;

/**
* Check if the commit message follow the guidelines
* @param {string} message - commit message
* @param {string} message commit message
* @returns {boolean} True if it's ok
* @private
*/
const isChoreTypePullRequest = TAG_REGEX.test.bind(TAG_REGEX);

/**
* Create the comment for the commit message issue
* @param {string} username - user to tag on the comment
* @param {string} username user to tag on the comment
* @returns {string} comment message
* @private
*/
Expand All @@ -37,8 +37,8 @@ If this is a mistake, then please ignore this message.

/**
* Checks if any unit test files are present in the pull request
* @param {Array<Object>} files - collection of files inside the pull request
* @param {string} repoUrl - url of the repo
* @param {Array<Object>} files collection of files inside the pull request
* @param {string} repoUrl url of the repo
* @returns {boolean} True if atleast 1 test files is present
* @private
*/
Expand All @@ -52,7 +52,7 @@ function areUnitTestFilesPresent(files, repoUrl) {

/**
* Adds the triage label if the issue has no labels on it
* @param {Object} context - context given by the probot
* @param {Object} context context given by the probot
* @returns {Promise.<void>} promise
* @private
*/
Expand Down
8 changes: 4 additions & 4 deletions src/plugins/commit-message/createMessage.js
Expand Up @@ -16,13 +16,13 @@ const ERROR_MESSAGES = {

/**
* Create a comment message body with the error details
* @param {Array<string>} errors - list of the error codes
* @param {boolean} isTitle - whether it is for title or the commit message
* @param {string} username - username of the PR author
* @param {Array<string>} errors list of the error codes
* @param {boolean} isTitle whether it is for title or the commit message
* @param {string} username username of the PR author
* @returns {string} the message to comment
* @private
*/
module.exports = function commentMessage(errors = [], isTitle = false, username) {
module.exports = function commentMessage(errors, isTitle, username) {
const errorMessages = [];

errors.forEach(err => {
Expand Down
16 changes: 8 additions & 8 deletions src/plugins/commit-message/index.js
Expand Up @@ -18,11 +18,11 @@ const { TAG_LABELS } = require("./util");
// Helpers
//-----------------------------------------------------------------------------

const TAG_REGEX = /^(?:feat|build|chore|docs|fix|refactor|test|ci|perf)!?: /;
const TAG_REGEX = /^(?:feat|build|chore|docs|fix|refactor|test|ci|perf)!?: /u;

const TAG_SPACE_REGEX = /^(?:[a-z]+!?: )/;
const TAG_SPACE_REGEX = /^(?:[a-z]+!?: )/u;

const LOWERCASE_TAG_REGEX = /^[a-z]/;
const LOWERCASE_TAG_REGEX = /^[a-z]/u;

const MESSAGE_LENGTH_LIMIT = 72;

Expand All @@ -37,12 +37,12 @@ const EXCLUDED_REPOSITORY_NAMES = new Set([

/**
* Apply different checks on the commit message
* @param {string} message - commit message
* @param {string} message commit message
* @returns {boolean} `true` if the commit message is valid
* @private
*/
function getCommitMessageErrors(message) {
const commitTitle = message.split(/\r?\n/)[0];
const commitTitle = message.split(/\r?\n/u)[0];
const errors = [];

if (message.startsWith("Revert \"")) {
Expand Down Expand Up @@ -72,20 +72,20 @@ function getCommitMessageErrors(message) {

/**
* Apply different checks on the commit message
* @param {string} message - commit message
* @param {string} message commit message
* @returns {Array<string>} The labels to add to the PR.
* @private
*/
function getCommitMessageLabels(message) {
const commitTitle = message.split(/\r?\n/)[0];
const commitTitle = message.split(/\r?\n/u)[0];
const [tag] = commitTitle.match(TAG_REGEX) || [""];

return TAG_LABELS.get(tag.trim());
}

/**
* If the first commit message is not legal then it adds a comment
* @param {Object} context - context given by the probot
* @param {Object} context context given by the probot
* @returns {Promise.<void>} promise
* @private
*/
Expand Down
12 changes: 6 additions & 6 deletions src/plugins/duplicate-comments/index.js
Expand Up @@ -16,7 +16,7 @@ const botType = "Bot";

/**
* Filters the comments based on the current user
* @param {Array<Object>} comments - collection of comments as returned by the github
* @param {Array<Object>} comments collection of comments as returned by the github
* @returns {Array<Object>} filtered comments
* @private
*/
Expand All @@ -26,7 +26,7 @@ function filterBotComments(comments) {

/**
* Extract the comment hash from the comment
* @param {string} comment - comment body
* @param {string} comment comment body
* @returns {string} comment hash
* @private
*/
Expand All @@ -40,7 +40,7 @@ function getCommentHash(comment) {
/**
* Creates the collection of comments based on the hash present inside the comments
* ignore the comments which doesnt have a hash
* @param {Array<Object>} comments - collection of comments as returned by the github
* @param {Array<Object>} comments collection of comments as returned by the github
* @returns {Map} comments by hash map
* @private
*/
Expand All @@ -65,7 +65,7 @@ function commentsByHash(comments) {

/**
* Filter comments that need to be deleted and return them
* @param {Map} commentsMap - comments collection by hash value inside the comment
* @param {Map} commentsMap comments collection by hash value inside the comment
* @returns {Array} Comments to be deleted
* @private
*/
Expand All @@ -83,7 +83,7 @@ function getCommentsTobeDeleted(commentsMap) {

/**
* Process the comments and return the comments which are duplicate and needs to be deleted
* @param {Array<Object>} comments - collection of comments as returned by the github
* @param {Array<Object>} comments collection of comments as returned by the github
* @returns {Array<Object>} comments to be deleted
* @private
*/
Expand All @@ -97,7 +97,7 @@ function processComments(comments) {

/**
* Checks for duplicates comments and removes all the duplicates leaving the last one
* @param {Object} context - context given by the probot
* @param {Object} context context given by the probot
* @returns {Promise.<void>} done when comments are removed
* @private
*/
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/issue-archiver/index.js
Expand Up @@ -25,8 +25,9 @@ async function hasArchivedLabel(context) {
/**
* Creates a search query to look for issuesin a given repo which have been closed for at least
* `ARCHIVAL_AGE_DAYS` days since the current date, and have not yet been archived.
* @param {string} options.owner The owner of the repo where issues should be searched
* @param {string} options.repo The name of the repo where issues should be searched
* @param {Object} options Repository where issues should be searched
* @param {string} options.owner The owner of the repository
* @param {string} options.repo The name of the repository
* @returns {string} A search query to send to the GitHub API
*/
function createSearchQuery({ owner, repo }) {
Expand Down Expand Up @@ -56,7 +57,6 @@ async function archiveIssue(context, issueNum) {
/**
* Gets all archived issues on the current repository
* @param {probot.Context} context Probot context for the current repository
* @param {string} searchQuery A search query to send to the GitHub API
* @returns {Promise<number[]>} A list of issue numbers that match the query
*/
async function getAllSearchResults(context) {
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/needs-info/index.js
Expand Up @@ -24,7 +24,7 @@ Thanks for your understanding.

/**
* Check if the needs info label is present or not
* @param {Object} label - added label object
* @param {Object} label added label object
* @returns {boolean} True if it does contain needs info label
* @private
*/
Expand All @@ -34,7 +34,7 @@ function hasNeedInfoLabel(label) {

/**
* If the label is need info then add the comment
* @param {Object} context - event payload from github
* @param {Object} context event payload from github
* @returns {undefined}
* @private
*/
Expand Down
12 changes: 6 additions & 6 deletions src/plugins/pr-ready-to-merge/common.js
Expand Up @@ -16,7 +16,7 @@ const labels = {

/**
* Removes the approved label from the pull request
* @param {Object} context - context given by the probot
* @param {Object} context context given by the probot
* @returns {Promise} Promise that fulfills when the action is complete
*/
function removePrApprovedLabel(context) {
Expand All @@ -27,7 +27,7 @@ function removePrApprovedLabel(context) {

/**
* Add the approved label to the pull request
* @param {Object} context - context given by the probot
* @param {Object} context context given by the probot
* @returns {Promise} Promise that fulfills when the action is complete
*/
function addPrApprovedLabel(context) {
Expand All @@ -40,8 +40,8 @@ function addPrApprovedLabel(context) {
* Gets all the pull request based on the sha
* it will return null if there is no related pr
* will return the first one if their are multiple entries (which should be rare)
* @param {Object} context - context given by the probot
* @param {string} sha - git sha value
* @param {Object} context context given by the probot
* @param {string} sha git sha value
* @returns {Promise.<Object|null>} Promise that fulfills when the action is complete
*/
async function getPullrequestBySha(context, sha) {
Expand All @@ -54,8 +54,8 @@ async function getPullrequestBySha(context, sha) {

/**
* Gets all the commits using the PR number
* @param {Object} context - context given by the probot
* @param {int} prId - pull request number
* @param {Object} context context given by the probot
* @param {int} prId pull request number
* @returns {Promise.<Array>} Resolves with commit collection
*/
async function getAllCommitsByPR(context, prId) {
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/pr-ready-to-merge/index.js
Expand Up @@ -14,7 +14,7 @@ const { isPrStatusSuccess } = require("./statusCheck");

/**
* Adds the triage label if the issue has no labels on it
* @param {Object} context - context given by the probot
* @param {Object} context context given by the probot
* @returns {Promise<void>} Promise that fulfills when the action is complete
* @private
*/
Expand All @@ -32,7 +32,7 @@ async function handleStatusChange(context) {

/**
* Adds the triage label if the issue has no labels on it
* @param {Object} context - context given by the probot
* @param {Object} context context given by the probot
* @returns {Promise<void>} Promise that fulfills when the action is complete
* @private
*/
Expand Down
14 changes: 7 additions & 7 deletions src/plugins/pr-ready-to-merge/reviewCheck.js
Expand Up @@ -9,8 +9,8 @@ const { getPullrequestBySha, labels } = require("./common");

/**
* Gets all the reviews for the PR number
* @param {Object} context - context given by the probot
* @param {int} prId - pull request number
* @param {Object} context context given by the probot
* @param {int} prId pull request number
* @returns {Promise.<Array>} Resolves with all reviews collection
*/
async function getAllReviewsByPR(context, prId) {
Expand All @@ -23,7 +23,7 @@ async function getAllReviewsByPR(context, prId) {

/**
* Sorts all the reviews by creating buckets based on the user
* @param {Array<Object>} allReviews - collection of reviews
* @param {Array<Object>} allReviews collection of reviews
* @returns {Map} Map of reviews to users
*/
function sortReviewsByUser(allReviews) {
Expand All @@ -40,7 +40,7 @@ function sortReviewsByUser(allReviews) {

/**
* Sorts all the reviews based on submitted date time
* @param {Array<Object>} allReviews - collection of sorted reviews
* @param {Array<Object>} allReviews collection of sorted reviews
* @returns {Array<Object>} A list of sorted reviews
*/
function sortReviewsByDtTm(allReviews) {
Expand All @@ -52,7 +52,7 @@ function sortReviewsByDtTm(allReviews) {
/**
* Check to see if atleast one review has been approved.
* if their are no reviews then it will say false
* @param {Map} allReviewsMap - Map of reviews to users
* @param {Map} allReviewsMap Map of reviews to users
* @returns {boolean} true id atleast one is approved
*/
function isAtleastOneApproved(allReviewsMap) {
Expand Down Expand Up @@ -86,8 +86,8 @@ function isAtleastOneApproved(allReviewsMap) {

/**
* Check if the review on the PR is good or not
* @param {Object} context - context given by the probot
* @param {string} sha - git sha value
* @param {Object} context context given by the probot
* @param {string} sha git sha value
* @returns {Promise.<boolean>} True if its good
*/
async function isPrReviewSuccess(context, sha) {
Expand Down

0 comments on commit 085a46a

Please sign in to comment.