Skip to content

Commit

Permalink
AG-31746 stop using getText for logging
Browse files Browse the repository at this point in the history
Merge in ADGUARD-FILTERS/scriptlets from fix/AG-31746 to master

Squashed commit of the following:

commit 6b69abd
Author: Maxim Topciu <mtopciu@adguard.com>
Date:   Wed Apr 17 12:51:45 2024 +0300

    AG-31746 fix changelog

commit da6f4f4
Author: Maxim Topciu <mtopciu@adguard.com>
Date:   Wed Apr 17 12:05:49 2024 +0300

    AG-31746 add changelog

commit 577f04c
Author: Maxim Topciu <mtopciu@adguard.com>
Date:   Tue Apr 16 13:01:47 2024 +0300

    AG-31746 fix typo

commit 4da4ad5
Author: Maxim Topciu <mtopciu@adguard.com>
Date:   Tue Apr 16 12:34:30 2024 +0300

    AG-31746 stop using getText for logging
  • Loading branch information
maximtop committed Apr 17, 2024
1 parent dc9b5cb commit 5fe6143
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 19 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ The format is based on [Keep a Changelog], and this project adheres to [Semantic
without needing the full rule text [#420]
- `trusted-dispatch-event` scriptlet [#382]

### Deprecated

- `ruleText` option in the `IConfiguration`

[Unreleased]: https://github.com/AdguardTeam/Scriptlets/compare/v1.10.25...HEAD
[#420]: https://github.com/AdguardTeam/Scriptlets/issues/420
[#382]: https://github.com/AdguardTeam/Scriptlets/issues/382
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ where:
* @property {'extension'|'corelibs'} engine — Defines the final form of scriptlet string presentation.
* @property {string} [version] — Extension version.
* @property {boolean} [verbose] — Flag to enable debug information printing to console.
* @property {string} [ruleText] — Source rule text, needed for debug purposes.
* @property {string} [ruleText]Deprecated: Source rule text, needed for debug purposes.
* @property {string} [domainName] — Domain name where scriptlet is applied, needed for debug purposes.
*/
```
Expand Down Expand Up @@ -494,7 +494,7 @@ scriptlets.isValidScriptletName(name);
*
* @returns {boolean} — True if scriptlet name is valid in rule.
*/
scriptlets.isValidScriptletRule(input);
scriptlets.isValidScriptletRule(ruleText);
```


Expand Down
2 changes: 1 addition & 1 deletion src/helpers/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ export const isValidScriptletRule = (ruleText: string): boolean => {
* @param modifiers rule modifiers
* @param redirectsData validator.REDIRECT_RULE_TYPES.(UBO|ADG)
* @param rule rule string
* @returns merker data object
* @returns marker data object
*/
const getMarkerData = (modifiers: string[], redirectsData: RedirectsData, rule: string): MarkerData => {
const { redirectRuleMarker, redirectMarker } = redirectsData;
Expand Down
17 changes: 3 additions & 14 deletions src/helpers/hit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,11 @@ export const hit = (source: Source) => {
const log = console.log.bind(console);
const trace = console.trace.bind(console);

let prefix = source.ruleText || '';

let prefix = '';
if (source.domainName) {
const AG_SCRIPTLET_MARKER = '#%#//';
const UBO_SCRIPTLET_MARKER = '##+js';
let ruleStartIndex;
if (source.ruleText.includes(AG_SCRIPTLET_MARKER)) {
ruleStartIndex = source.ruleText.indexOf(AG_SCRIPTLET_MARKER);
} else if (source.ruleText.includes(UBO_SCRIPTLET_MARKER)) {
ruleStartIndex = source.ruleText.indexOf(UBO_SCRIPTLET_MARKER);
}
// delete all domains from ruleText and leave just rule part
const rulePart = source.ruleText.slice(ruleStartIndex);
// prepare applied scriptlet rule for specific domain
prefix = `${source.domainName}${rulePart}`;
prefix += `${source.domainName}`;
}
prefix += `#%#//scriptlet('${source.name}', '${source.args.join(', ')}')`;

log(`${prefix} trace start`);
if (trace) {
Expand Down
6 changes: 4 additions & 2 deletions types/scriptlets.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ declare module '@adguard/scriptlets' {
verbose: boolean;

/**
* Source rule text is used for debugging purposes
* Source rule text is used for debugging purposes.
*
* @deprecated since it is not used in the code anymore.
*/
ruleText: string;
ruleText?: string;

/**
* Domain name, used to improve logging
Expand Down

0 comments on commit 5fe6143

Please sign in to comment.