Skip to content

Commit

Permalink
change the name of the include directive option
Browse files Browse the repository at this point in the history
  • Loading branch information
jellizaveta committed May 3, 2024
1 parent a31621b commit 390862d
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- New `@include` directive option `/optimizeBaseRules` [#217]
- New `@include` directive option `/optimizeDomainBlockingRules` [#217]

### Removed

Expand Down
12 changes: 6 additions & 6 deletions src/main/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = (function () {
const workaround = require('./utils/workaround');
const webutils = require('./utils/webutils');
const { getFilterIdFromDirName } = require('./utils/utils');
const { optimizeBaseRules } = require('./utils/builder-utils');
const { optimizeDomainBlockingRules } = require('./utils/builder-utils');

const FiltersDownloader = require('@adguard/filters-downloader');

Expand All @@ -36,7 +36,7 @@ module.exports = (function () {
const MODIFIERS_SEPARATOR = '$';
const INCLUDE_DIRECTIVE = '@include ';
const STRIP_COMMENTS_OPTION = 'stripComments';
const OPTIMIZE_BASE_RULES = 'optimizeBaseRules';
const OPTIMIZE_DOMAIN_BLOCKING_RULES = 'optimizeDomainBlockingRules';
const NOT_OPTIMIZED_OPTION = 'notOptimized';
const EXCLUDE_OPTION = 'exclude';
const ADD_MODIFIERS_OPTION = 'addModifiers';
Expand Down Expand Up @@ -319,8 +319,8 @@ module.exports = (function () {
const attribute = parts[i].trim();
if (attribute.startsWith(`${SLASH}${STRIP_COMMENTS_OPTION}`)) {
options.push({ name: STRIP_COMMENTS_OPTION, value: true });
} else if (attribute.startsWith(`${SLASH}${OPTIMIZE_BASE_RULES}`)) {
options.push({ name: OPTIMIZE_BASE_RULES, value: true });
} else if (attribute.startsWith(`${SLASH}${OPTIMIZE_DOMAIN_BLOCKING_RULES}`)) {
options.push({ name: OPTIMIZE_DOMAIN_BLOCKING_RULES, value: true });
} else if (attribute.startsWith(`${SLASH}${NOT_OPTIMIZED_OPTION}`)) {
options.push({ name: NOT_OPTIMIZED_OPTION, value: true });
} else if (attribute.startsWith(`${SLASH}${EXCLUDE_OPTION}${EQUAL_SIGN}`)) {
Expand Down Expand Up @@ -408,8 +408,8 @@ module.exports = (function () {
case STRIP_COMMENTS_OPTION:
includedLines = stripComments(includedLines);
break;
case OPTIMIZE_BASE_RULES:
includedLines = optimizeBaseRules(includedLines);
case OPTIMIZE_DOMAIN_BLOCKING_RULES:
includedLines = optimizeDomainBlockingRules(includedLines);
break;
case NOT_OPTIMIZED_OPTION:
includedLines = addNotOptimizedHints(includedLines);
Expand Down
4 changes: 2 additions & 2 deletions src/main/utils/builder-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const DOT = '.';
* @param {string[]} lines - An array of text lines.
* @returns {string[]} - An array of of text lines with redundant rules removed.
*/
const optimizeBaseRules = function (lines) {
const optimizeDomainBlockingRules = function (lines) {
/**
* Modifies string to handle domains without rule markers
*
Expand Down Expand Up @@ -108,5 +108,5 @@ const optimizeBaseRules = function (lines) {
};

module.exports = {
optimizeBaseRules,
optimizeDomainBlockingRules,
};
2 changes: 1 addition & 1 deletion src/test/builder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('Test builder', () => {
expect(revision.timeUpdated).toBeTruthy();
});

describe('optimizeBaseRules options of include directive', () => {
describe('optimizeDomainBlockingRules options of include directive', () => {
it('Should filter "platforms/mac" with "12.txt"', async () => {
// Read the content of the file and split it into lines
const filterContent = await readFile(path.join(platformsDir, 'mac', 'filters', '12.txt'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
! License: http://creativecommons.org/licenses/by-sa/3.0/
!
!#if (adguard_app_mac)
@include ../cname_trackers_2.txt /optimizeBaseRules /addModifiers="script"
@include ../cname_trackers_2.txt /optimizeDomainBlockingRules /addModifiers="script"
!#endif
!#if (adguard_app_ios)
@include ../cname_trackers_2.txt /optimizeBaseRules
@include ../cname_trackers_2.txt /optimizeDomainBlockingRules
!#endif
!#if (adguard_ext_edge)
@include ../cname_trackers_2.txt /optimizeBaseRules /notOptimized
@include ../cname_trackers_2.txt /optimizeDomainBlockingRules /notOptimized
!#endif
10 changes: 5 additions & 5 deletions src/test/utils/builder-utils.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const { optimizeBaseRules } = require('../../main/utils/builder-utils');
const { optimizeDomainBlockingRules } = require('../../main/utils/builder-utils');

jest.mock('../../main/utils/log');

describe('optimizeBaseRules options of include directive', () => {
describe('optimizeDomainBlockingRules options of include directive', () => {
it('Properly removes redundant rules', () => {
const lines = [
'||example.com^',
Expand All @@ -11,7 +11,7 @@ describe('optimizeBaseRules options of include directive', () => {
'||anotherexample.com^',
];
const expectedOutput = ['||example.com^', '||anotherexample.com^'];
const result = optimizeBaseRules(lines);
const result = optimizeDomainBlockingRules(lines);
expect(result).toEqual(expectedOutput);
});

Expand All @@ -21,7 +21,7 @@ describe('optimizeBaseRules options of include directive', () => {
'||anotherexample.com^',
];
const expectedOutput = ['||example.com^', '||anotherexample.com^'];
const result = optimizeBaseRules(lines);
const result = optimizeDomainBlockingRules(lines);
expect(result).toEqual(expectedOutput);
});

Expand All @@ -40,7 +40,7 @@ describe('optimizeBaseRules options of include directive', () => {
'||anotherexample.com^$image',
'host.com',
];
const result = optimizeBaseRules(lines);
const result = optimizeDomainBlockingRules(lines);
expectedOutput.forEach((rule) => {
expect(result.includes(rule)).toBeTruthy();
});
Expand Down

0 comments on commit 390862d

Please sign in to comment.