Skip to content
Open
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
8 changes: 0 additions & 8 deletions .eslintignore

This file was deleted.

21 changes: 0 additions & 21 deletions .eslintrc.json

This file was deleted.

10 changes: 5 additions & 5 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ jobs:
name: ESLint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install node v14
uses: actions/setup-node@v2
- uses: actions/checkout@v4
- name: Install node v24
uses: actions/setup-node@v4
with:
node-version: '14'
node-version: '24'
- name: Install dependencies
run: npm install
- name: Run ESLint
run: ./node_modules/.bin/eslint .
run: npm run lint
55 changes: 55 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import globals from 'globals';
import pluginEslintJs from '@eslint/js';
import pluginMocha from 'eslint-plugin-mocha';
import configEslintConfigPrettier from 'eslint-plugin-prettier/recommended';

export default [
pluginEslintJs.configs.recommended,
{
name: 'whatsapp-web.js/default/rules',
plugins: {
mocha: pluginMocha,
},
languageOptions: {
// // TODO: consider moving to:
// ecmaVersion: 2025,
ecmaVersion: 2022,

globals: {
...globals.browser,
...globals.commonjs,
...globals.es6,
...globals.node,

Atomics: 'readonly',
SharedArrayBuffer: 'readonly',
},
},
rules: {
'no-unused-vars': [
'error',
{
// TODO: args can be uncommented, but there is code, that causes lint-errors
// args: 'all',
vars: 'all',
caughtErrorsIgnorePattern: '^ignoreError',
},
],
},
},
{
name: 'whatsapp-web.js/default/ignores',
ignores: [
'node_modules',
'dist',
'coverage',
'docs',
'*.min.js',
'.wa-version',
'.wwebjs_auth',
'.wwebjs_cache',
],
},
pluginMocha.configs.recommended,
configEslintConfigPrettier,
];
1 change: 1 addition & 0 deletions example.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ client.on('message', async (msg) => {
await client.acceptInvite(inviteCode);
msg.reply('Joined the group!');
} catch (e) {
console.error(e);
msg.reply('That invite code seems to be invalid.');
}
} else if (msg.body.startsWith('!addmembers')) {
Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,20 @@
"puppeteer": "^24.31.0"
},
"devDependencies": {
"is-ci": "^4.1.0",
"@commitlint/cli": "^20.4.1",
"@commitlint/config-conventional": "^20.4.1",
"@eslint/js": "^9.39.4",
"@types/node-fetch": "^2.5.12",
"chai": "^4.3.4",
"chai-as-promised": "^7.1.1",
"dotenv": "^16.0.0",
"eslint": "^8.4.1",
"eslint": "^9.39.4",
"eslint-config-prettier": "^10.1.8",
"eslint-plugin-mocha": "^10.0.3",
"eslint-plugin-mocha": "^11.2.0",
"eslint-plugin-prettier": "^5.5.5",
"globals": "^17.4.0",
"husky": "^9.1.7",
"is-ci": "^4.1.0",
"jsdoc": "^3.6.4",
"jsdoc-baseline": "^0.1.5",
"lint-staged": "^16.2.7",
Expand Down
7 changes: 4 additions & 3 deletions src/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ class Client extends EventEmitter {

Util.setFfmpegPath(this.options.ffmpegPath);
}

/**
* Injection logic
* Private function
Expand Down Expand Up @@ -322,7 +323,7 @@ class Client extends EventEmitter {
await webCache.persist(this.currentIndexHtml, version);
}

//Load util functions (serializers, helper functions)
// Load util functions (serializers, helper functions)
await this.pupPage.evaluate(LoadUtils);

let start = Date.now();
Expand Down Expand Up @@ -2327,7 +2328,7 @@ class Client extends EventEmitter {
},
participantWids,
);
} catch (err) {
} catch (ignoreError) {
return 'CreateGroupError: An unknown error occupied while creating a group';
}

Expand Down Expand Up @@ -2566,7 +2567,7 @@ class Client extends EventEmitter {
meContact,
));
}
} catch (error) {
} catch (ignoreError) {
return false;
}

Expand Down
2 changes: 2 additions & 0 deletions src/authStrategies/BaseAuthStrategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class BaseAuthStrategy {
setup(client) {
this.client = client;
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are "stylistic changes":

  1. add empty lines
  2. add a <space> for inline comments
  3. replace unused err (or _, or other names) with ignoredError
  4. and there are two lines i didn't want to change - so i've added "eslint-ignore" to them

async beforeBrowserInitialized() {}
async afterBrowserInitialized() {}
async onAuthenticationNeeded() {
Expand All @@ -17,6 +18,7 @@ class BaseAuthStrategy {
failureEventPayload: undefined,
};
}

async getAuthEventPayload() {}
async afterAuthReady() {}
async disconnect() {}
Expand Down
1 change: 1 addition & 0 deletions src/structures/Label.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Label extends Base {
*/
this.hexColor = labelData.hexColor;
}

/**
* Get all chats that have been assigned this Label
* @returns {Promise<Array<Chat>>}
Expand Down
2 changes: 2 additions & 0 deletions src/structures/Message.js
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,7 @@ class Message extends Base {
}
return undefined;
}

/**
* Gets the payment details associated with a given message
* @return {Promise<Payment>}
Expand Down Expand Up @@ -1006,6 +1007,7 @@ class Message extends Base {

return edittedEventMsg && new Message(this.client, edittedEventMsg);
}

/**
* Returns the PollVote this poll message
* @returns {Promise<PollVote[]>}
Expand Down
14 changes: 7 additions & 7 deletions src/util/Injected/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ exports.LoadUtils = () => {
.vcardGetNameFromParsed(parsed),
};
}
} catch (_) {
} catch (ignoreError) {
// not a vcard
}
}
Expand Down Expand Up @@ -361,7 +361,7 @@ exports.LoadUtils = () => {
content = options.buttons.body;
caption = content;
} else {
caption = options.caption ? options.caption : ' '; //Caption can't be empty
caption = options.caption ? options.caption : ' '; // Caption can't be empty
}
buttonOptions = {
productHeaderImageRejected: false,
Expand Down Expand Up @@ -857,7 +857,7 @@ exports.LoadUtils = () => {
.require('WAWebCollections')
.WAWebNewsletterCollection.find(chatWid);
}
} catch (err) {
} catch (ignoreError) {
chat = null;
}
} else {
Expand Down Expand Up @@ -1181,7 +1181,7 @@ exports.LoadUtils = () => {
);

return waveform;
} catch (e) {
} catch (ignoreError) {
return undefined;
}
};
Expand Down Expand Up @@ -1418,7 +1418,7 @@ exports.LoadUtils = () => {
return base64Image;
}
}
} catch (error) {
} catch (ignoreError) {
/* empty */
}
}
Expand Down Expand Up @@ -1455,7 +1455,7 @@ exports.LoadUtils = () => {
rpcResult.value.addParticipant[0]
.addParticipantsParticipantAddedOrNonRegisteredWaUserParticipantErrorLidResponseMixinGroup
.value.addParticipantsParticipantMixins;
} catch (err) {
} catch (ignoreError) {
data.code = 400;
return data;
}
Expand Down Expand Up @@ -1618,7 +1618,7 @@ exports.LoadUtils = () => {
));
}
return result;
} catch (err) {
} catch (ignoreError) {
return [];
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/webCache/LocalWebCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class LocalWebCache extends WebCache {

try {
return fs.readFileSync(filePath, 'utf-8');
} catch (err) {
} catch (ignoreError) {
if (this.strict)
throw new VersionResolveError(
`Couldn't load version ${version} from the cache`,
Expand Down
1 change: 1 addition & 0 deletions src/webCache/WebCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class WebCache {
async resolve() {
return null;
}

async persist() {}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ END:VCARD`;
it('can send multiple Contacts as a contact card message', async function () {
const contact1 = await client.getContactById(remoteId);
const contact2 =
await client.getContactById('5511942167462@c.us'); //iFood
await client.getContactById('5511942167462@c.us'); // iFood

const msg = await client.sendMessage(remoteId, [
contact1,
Expand Down
2 changes: 1 addition & 1 deletion tests/structures/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ describe('Chat', function () {
});
});

// eslint-disable-next-line mocha/no-skipped-tests
// eslint-disable-next-line mocha/no-pending-tests
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this rule was renamed in the newest versions of the eslint-mocha plugin

describe.skip('Destructive operations', function () {
it('can clear all messages from chat', async function () {
const res = await chat.clearMessages();
Expand Down
Loading