@adguard/hostlist-compiler 1.0.19 → 1.0.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.eslintrc.js ADDED
@@ -0,0 +1,27 @@
1
+ module.exports = {
2
+ extends: [
3
+ 'airbnb-base',
4
+ ],
5
+ parser: '@babel/eslint-parser',
6
+ parserOptions: {
7
+ requireConfigFile: false,
8
+ },
9
+ env: {
10
+ browser: false,
11
+ node: true,
12
+ jest: true,
13
+ },
14
+ rules: {
15
+ 'max-len': [
16
+ 'error',
17
+ {
18
+ code: 120,
19
+ ignoreUrls: true,
20
+ },
21
+ ],
22
+ indent: ['error', 4, { SwitchCase: 1 }],
23
+ 'import/prefer-default-export': 'off',
24
+ 'arrow-body-style': 'off',
25
+ 'import/no-extraneous-dependencies': 'off',
26
+ },
27
+ };
@@ -92,8 +92,7 @@ notifications:
92
92
  recipients:
93
93
  - webhook:
94
94
  name: Build webhook
95
- # TODO: maybe channel should be 'adguard-filters'
96
- url: http://prod.jirahub.service.eu.consul/v1/webhook/bamboo?channel=adguard-qa
95
+ url: http://prod.jirahub.service.eu.consul/v1/webhook/bamboo
97
96
 
98
97
  labels: []
99
98
 
@@ -42,5 +42,4 @@ npmjs:
42
42
  recipients:
43
43
  - webhook:
44
44
  name: Deploy webhook
45
- # TODO: maybe channel should be 'adguard-filters'
46
- url: http://prod.jirahub.service.eu.consul/v1/webhook/bamboo?channel=adguard-qa
45
+ url: http://prod.jirahub.service.eu.consul/v1/webhook/bamboo
@@ -57,8 +57,7 @@ notifications:
57
57
  recipients:
58
58
  - webhook:
59
59
  name: Build webhook
60
- # TODO: maybe channel should be 'adguard-filters'
61
- url: http://prod.jirahub.service.eu.consul/v1/webhook/bamboo?channel=adguard-qa
60
+ url: http://prod.jirahub.service.eu.consul/v1/webhook/bamboo
62
61
 
63
62
  labels: []
64
63
  other:
package/jest.config.js CHANGED
@@ -1,3 +1,4 @@
1
1
  module.exports = {
2
2
  testEnvironment: 'node',
3
+ silent: true,
3
4
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adguard/hostlist-compiler",
3
- "version": "1.0.19",
3
+ "version": "1.0.23",
4
4
  "description": "A simple tool that compiles hosts blocklists from multiple sources",
5
5
  "main": "src/index.js",
6
6
  "types": "src/index.d.ts",
@@ -12,16 +12,17 @@
12
12
  },
13
13
  "scripts": {
14
14
  "lint": "eslint . --cache",
15
- "test": "jest --runInBand .",
15
+ "test": "jest --runInBand --detectOpenHandles .",
16
16
  "increment": "yarn version --patch --no-git-tag-version",
17
17
  "build-txt": "node tools/build-txt.js",
18
18
  "compile": "node src/cli.js"
19
19
  },
20
20
  "devDependencies": {
21
- "babel-eslint": "^10.1.0",
22
- "eslint": "^6.8.0",
23
- "eslint-config-airbnb": "^18.0.1",
24
- "eslint-plugin-import": "^2.20.1",
21
+ "@babel/core": "^7.21.0",
22
+ "@babel/eslint-parser": "^7.19.1",
23
+ "eslint": "^8.34.0",
24
+ "eslint-config-airbnb-base": "^15.0.0",
25
+ "eslint-plugin-import": "^2.27.5",
25
26
  "jest": "^25.1.0",
26
27
  "mock-fs": "^4.11.0",
27
28
  "nock": "^12.0.2"
package/src/cli.js CHANGED
@@ -26,6 +26,7 @@ const { argv } = require('yargs')
26
26
  alias: 'i',
27
27
  array: true,
28
28
  type: 'string',
29
+ // eslint-disable-next-line max-len
29
30
  description: 'URL (or path to a file) to convert to an AdGuard-syntax blocklist. Can be specified multiple times.',
30
31
  })
31
32
  .option('input-type', {
@@ -128,4 +129,3 @@ async function main() {
128
129
  }
129
130
 
130
131
  main();
131
- return 0;
package/src/rule.js CHANGED
@@ -1,6 +1,7 @@
1
1
  const _ = require('lodash');
2
2
  const utils = require('./utils');
3
3
 
4
+ // eslint-disable-next-line max-len
4
5
  const domainRegex = /^(?=.{1,255}$)[0-9A-Za-z](?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?(?:\.[0-9A-Za-z](?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?)*\.?$/;
5
6
  const etcHostsRegex = /^([a-f0-9.:\][]+)(%[a-z0-9]+)?\s+([^#]+)(#.*)?$/;
6
7
 
@@ -13,7 +13,8 @@ function removeModifiers(rules) {
13
13
  const filtered = [];
14
14
 
15
15
  let modifiedCount = 0;
16
- rules.forEach((ruleText) => {
16
+ rules.forEach((rawRuleText) => {
17
+ const ruleText = rawRuleText.trim();
17
18
  if (_.isEmpty(ruleText) || ruleUtils.isComment(ruleText)) {
18
19
  filtered.push(ruleText);
19
20
  return;
@@ -42,10 +42,16 @@ async function transform(rules, configuration, transformations) {
42
42
 
43
43
  let transformed = rules;
44
44
 
45
- transformed = await exclude(transformed, configuration.exclusions,
46
- configuration.exclusions_sources);
47
- transformed = await include(transformed, configuration.inclusions,
48
- configuration.inclusions_sources);
45
+ transformed = await exclude(
46
+ transformed,
47
+ configuration.exclusions,
48
+ configuration.exclusions_sources,
49
+ );
50
+ transformed = await include(
51
+ transformed,
52
+ configuration.inclusions,
53
+ configuration.inclusions_sources,
54
+ );
49
55
 
50
56
  if (transformations.indexOf(TRANSFORMATIONS.TrimLines) !== -1) {
51
57
  transformed = trimLines(transformed);
@@ -12,6 +12,7 @@ const SUPPORTED_MODIFIERS = [
12
12
  '~important',
13
13
  'badfilter',
14
14
  'ctag',
15
+ 'denyallow',
15
16
  ];
16
17
 
17
18
  /**
@@ -33,8 +33,11 @@ describe('Exclusions', () => {
33
33
  const rules = ['rule1', 'rule2', 'rule3', 'rule4', 'rule5', ''];
34
34
 
35
35
  // Exclude!
36
- const filtered = await exclude(rules, ['rule4'],
37
- ['https://example.org/exclusions.txt', 'https://example.org/exclusions2.txt', 'test/dir/exclusions.txt']);
36
+ const filtered = await exclude(
37
+ rules,
38
+ ['rule4'],
39
+ ['https://example.org/exclusions.txt', 'https://example.org/exclusions2.txt', 'test/dir/exclusions.txt'],
40
+ );
38
41
 
39
42
  // Assert
40
43
  expect(filtered).toHaveLength(2);
@@ -1,8 +1,10 @@
1
1
  const removeModifiers = require('../../src/transformations/remove-modifiers');
2
2
 
3
- describe('Strip third-party', () => {
3
+ describe('Remove modifiers', () => {
4
4
  it('simple test', () => {
5
- const rules = `! test comment
5
+ const actual = `! test comment
6
+ ! next line should have whitespaces. do not remove them. AG-23720
7
+
6
8
  ||example.org$third-party,important
7
9
  ||example.net$domain=ya.ru,3p
8
10
  ||islandofadvert.com^$document,popup
@@ -10,16 +12,21 @@ describe('Strip third-party', () => {
10
12
  ||example.com$doc
11
13
  ||example.com$all
12
14
  ||example.org^`.split(/\r?\n/);
13
- const filtered = removeModifiers(rules);
14
15
 
15
- expect(filtered).toHaveLength(8);
16
- expect(filtered[0]).toBe('! test comment');
17
- expect(filtered[1]).toBe('||example.org$important');
18
- expect(filtered[2]).toBe('||example.net$domain=ya.ru');
19
- expect(filtered[3]).toBe('||islandofadvert.com^');
20
- expect(filtered[4]).toBe('||example.com');
21
- expect(filtered[5]).toBe('||example.com');
22
- expect(filtered[6]).toBe('||example.com');
23
- expect(filtered[7]).toBe('||example.org^');
16
+ const expected = [
17
+ '! test comment',
18
+ '! next line should have whitespaces. do not remove them. AG-23720',
19
+ // whitespaces should be trimmed
20
+ '',
21
+ '||example.org$important',
22
+ '||example.net$domain=ya.ru',
23
+ '||islandofadvert.com^',
24
+ '||example.com',
25
+ '||example.com',
26
+ '||example.com',
27
+ '||example.org^',
28
+ ];
29
+
30
+ expect(removeModifiers(actual)).toStrictEqual(expected);
24
31
  });
25
32
  });
@@ -44,6 +44,8 @@ describe('Validate', () => {
44
44
  ||org^
45
45
  ||example.org^$third-party
46
46
  ||example.org^$important
47
+ ||*.ga^$denyallow=example1.ga|example2.ga
48
+ ://ww4.$denyallow=ww4.example.com
47
49
  ://example.org
48
50
  ||example.org^|
49
51
  @@||example.org^|$important
@@ -57,6 +59,8 @@ describe('Validate', () => {
57
59
  '||example.org^',
58
60
  '||ex*.org^', // valid because contains special characters
59
61
  '||example.org^$important',
62
+ '||*.ga^$denyallow=example1.ga|example2.ga',
63
+ '://ww4.$denyallow=ww4.example.com',
60
64
  '://example.org',
61
65
  '||example.org^|',
62
66
  '@@||example.org^|$important',
package/.eslintrc DELETED
@@ -1,16 +0,0 @@
1
- {
2
- "extends": "airbnb-base",
3
- "env": {
4
- "browser": false,
5
- "node": true,
6
- "jest": true
7
- },
8
- "rules": {
9
- "indent": [
10
- "error",
11
- 4
12
- ],
13
- "import/no-extraneous-dependencies": 0
14
- },
15
- "parser": "babel-eslint"
16
- }