Skip to content

Commit

Permalink
enable rules for helpers p2
Browse files Browse the repository at this point in the history
  • Loading branch information
stanislav-atr committed Dec 29, 2022
1 parent 279c589 commit c49ebf4
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 59 deletions.
26 changes: 13 additions & 13 deletions src/helpers/request-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { getObjectFromEntries } from './object-utils';
* Returns array of request props that are supported by fetch/xhr scriptlets.
* Includes common 'url' and 'method' props and all other fetch-specific props
*
* @returns {string[]}
* @returns {string[]} list of request props
*/
export const getRequestProps = () => [
'url',
Expand All @@ -26,7 +26,7 @@ export const getRequestProps = () => [
/**
* Collects Request options to object
*
* @param {Request} request
* @param {Request} request Request instance to collect properties from
* @returns {object} data object
*/
export const getRequestData = (request) => {
Expand Down Expand Up @@ -74,12 +74,12 @@ export const getFetchData = (args) => {
/**
* Collect xhr.open arguments to object
*
* @param {string} method
* @param {string} url
* @param {string} async
* @param {string} user
* @param {string} password
* @returns {object}
* @param {string} method request method
* @param {string} url request url
* @param {string} async request async prop
* @param {string} user request user prop
* @param {string} password request password prop
* @returns {object} aggregated request data
*/
export const getXhrData = (method, url, async, user, password) => {
return {
Expand All @@ -95,7 +95,7 @@ export const getXhrData = (method, url, async, user, password) => {
* Parse propsToMatch input string into object;
* used for prevent-fetch and prevent-xhr
*
* @param {string} propsToMatchStr
* @param {string} propsToMatchStr string of space-separated request properties to match
* @returns {object} object where 'key' is prop name and 'value' is prop value
*/
export const parseMatchProps = (propsToMatchStr) => {
Expand Down Expand Up @@ -129,8 +129,8 @@ export const parseMatchProps = (propsToMatchStr) => {
/**
* Validates parsed data values
*
* @param {object} data
* @returns {boolean}
* @param {object} data request data
* @returns {boolean} if data is valid
*/
export const validateParsedData = (data) => {
return Object.values(data)
Expand All @@ -140,8 +140,8 @@ export const validateParsedData = (data) => {
/**
* Converts valid parsed data to data obj for further matching
*
* @param {object} data
* @returns {object}
* @param {object} data parsed request data
* @returns {object} data obj ready for matching
*/
export const getMatchPropsData = (data) => {
const matchData = {};
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/script-source-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { startsWith } from './string-utils';
*
* @param {string|undefined} stackMatch - input stack value to match
* @param {string} stackTrace - script error stack trace
* @returns {boolean}
* @returns {boolean} if stacks match
*/
export const shouldAbortInlineOrInjectedScript = (stackMatch, stackTrace) => {
const INLINE_SCRIPT_STRING = 'inlineScript';
Expand Down
6 changes: 3 additions & 3 deletions src/helpers/storage-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import { logMessage } from './log-message';
/**
* Sets item to a specified storage, if storage isn't full.
*
* @param {Source} source
* @param {Source} source scriptlet's configuration
* @param {Storage} storage storage instance to set item into
* @param {string} key
* @param {string} value
* @param {string} key storage key
* @param {string} value staroge value
*/
export const setStorageItem = (source, storage, key, value) => {
// setItem() may throw an exception if the storage is full.
Expand Down
52 changes: 26 additions & 26 deletions src/helpers/string-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ import {
* @param {string} input input string
* @param {string} substr to look for
* @param {string} newSubstr replacement
* @returns {string}
* @returns {string} result string
*/
export const replaceAll = (input, substr, newSubstr) => input.split(substr).join(newSubstr);

/**
* Escapes special chars in string
*
* @param {string} str
* @returns {string}
* @param {string} str raw string
* @returns {string} string with escaped special characters
*/
export const escapeRegExp = (str) => str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');

Expand Down Expand Up @@ -56,7 +56,7 @@ export const toRegExp = (input = '') => {
* Checks whether the input string can be converted to regexp
*
* @param {RawStrPattern} input literal string or regexp pattern
* @returns {boolean}
* @returns {boolean} if input can be converted to regexp
*/
export const isValidStrPattern = (input) => {
const FORWARD_SLASH = '/';
Expand All @@ -78,9 +78,9 @@ export const isValidStrPattern = (input) => {
/**
* Get string before regexp first match
*
* @param {string} str
* @param {RegExp} rx
* @returns {string}
* @param {string} str input string
* @param {RegExp} rx find pattern
* @returns {string} result string
*/
export const getBeforeRegExp = (str, rx) => {
const index = str.search(rx);
Expand All @@ -92,7 +92,7 @@ export const getBeforeRegExp = (str, rx) => {
*
* @param {string} str full string
* @param {string} prefix substring
* @returns {boolean}
* @returns {boolean} if string start with the substring
*/
export const startsWith = (str, prefix) => {
// if str === '', (str && false) will return ''
Expand All @@ -105,7 +105,7 @@ export const startsWith = (str, prefix) => {
*
* @param {string} str full string
* @param {string} ending substring
* @returns {boolean}
* @returns {boolean} string ends with the substring
*/
export const endsWith = (str, ending) => {
// if str === '', (str && false) will return ''
Expand All @@ -132,8 +132,8 @@ export const substringBefore = (str, separator) => {
/**
* Wrap str in single quotes and replaces single quotes to double one
*
* @param {string} str
* @returns {string}
* @param {string} str input string
* @returns {string} string with swapped quotes
*/
export const wrapInSingleQuotes = (str) => {
if ((str[0] === '\'' && str[str.length - 1] === '\'')
Expand All @@ -149,8 +149,8 @@ export const wrapInSingleQuotes = (str) => {
/**
* Returns substring enclosed in the widest braces
*
* @param {string} str
* @returns {string}
* @param {string} str input string
* @returns {string} substring
*/
export const getStringInBraces = (str) => {
const firstIndex = str.indexOf('(');
Expand All @@ -161,7 +161,7 @@ export const getStringInBraces = (str) => {
/**
* Prepares RTCPeerConnection config as string for proper logging
*
* @param {*} config
* @param {*} config RTC config
* @returns {string} stringified config
*/
export const convertRtcConfigToString = (config) => {
Expand Down Expand Up @@ -194,7 +194,7 @@ export const convertRtcConfigToString = (config) => {
* used for match inputs with possible negation
*
* @param {string} match literal string or regexp pattern
* @returns {boolean}
* @returns {boolean} true if input can be converted to regexp
*/
export const isValidMatchStr = (match) => {
const INVERT_MARKER = '!';
Expand All @@ -210,7 +210,7 @@ export const isValidMatchStr = (match) => {
* used for match inputs with possible negation
*
* @param {string} match string of match number
* @returns {boolean}
* @returns {boolean} if match number is valid
*/
export const isValidMatchNumber = (match) => {
const INVERT_MARKER = '!';
Expand All @@ -233,8 +233,8 @@ export const isValidMatchNumber = (match) => {
* Needed for prevent-setTimeout, prevent-setInterval,
* prevent-requestAnimationFrame and prevent-window-open
*
* @param {string} match
* @returns {MatchData}
* @param {string} match matching arg
* @returns {MatchData} data prepared for matching
*/
export const parseMatchArg = (match) => {
const INVERT_MARKER = '!';
Expand All @@ -254,8 +254,8 @@ export const parseMatchArg = (match) => {
* Parses delay arg with possible negation for no matching.
* Needed for prevent-setTimeout and prevent-setInterval
*
* @param {string} delay
* @returns {DelayData} `{ isInvertedDelayMatch, delayMatch }` where:
* @param {string} delay scriptlet's delay arg
* @returns {DelayData} parsed delay data
*/
export const parseDelayArg = (delay) => {
const INVERT_MARKER = '!';
Expand All @@ -270,7 +270,7 @@ export const parseDelayArg = (delay) => {
* Converts object to string for logging
*
* @param {object} obj data object
* @returns {string}
* @returns {string} object's string representation
*/
export const objectToString = (obj) => {
return isEmptyObject(obj)
Expand All @@ -291,8 +291,8 @@ export const objectToString = (obj) => {
/**
* Converts types into a string
*
* @param {*} value
* @returns {string}
* @param {*} value input value type
* @returns {string} type's string representation
*/
export const convertTypeToString = (value) => {
let output;
Expand All @@ -314,8 +314,8 @@ export const convertTypeToString = (value) => {
/**
* Generate a random string, a length of the string is provided as an argument
*
* @param {number} length
* @returns {string}
* @param {number} length output's length
* @returns {string} random string
*/
export function getRandomStrByLength(length) {
let result = '';
Expand All @@ -330,7 +330,7 @@ export function getRandomStrByLength(length) {
/**
* Generate a random string
*
* @param {string} customResponseText
* @param {string} customResponseText response text to include in output
* @returns {string|null} random string or null if passed argument is invalid
*/
export function generateRandomResponse(customResponseText) {
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/throttle.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Returns a wrapper, passing the call to 'method' at maximum once per 'delay' milliseconds.
* Those calls that fall into the "cooldown" period, are ignored
*
* @param {Function} cb
* @param {Function} cb callback
* @param {number} delay - milliseconds
* @returns {Function} throttled callback
*/
Expand Down
30 changes: 15 additions & 15 deletions src/helpers/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ const COMMENT_MARKER = '!';
/**
* Checks if rule text is comment e.g. !!example.org##+js(set-constant.js, test, false)
*
* @param {string} rule
* @returns {boolean}
* @param {string} rule rule text
* @returns {boolean} if rule text is comment
*/
const isComment = (rule) => startsWith(rule, COMMENT_MARKER);

Expand Down Expand Up @@ -54,7 +54,7 @@ const ADG_CSS_MASK_REG = /#@?\$#.+?\s*\{.*\}\s*$/g;
* Checks if the `rule` is AdGuard scriptlet rule
*
* @param {string} rule - rule text
* @returns {boolean}
* @returns {boolean} if given rule is adg rule
*/
const isAdgScriptletRule = (rule) => {
return (
Expand All @@ -67,7 +67,7 @@ const isAdgScriptletRule = (rule) => {
* Checks if the `rule` is uBO scriptlet rule
*
* @param {string} rule rule text
* @returns {boolean}
* @returns {boolean} if given rule is ubo rule
*/
const isUboScriptletRule = (rule) => {
return (
Expand All @@ -84,7 +84,7 @@ const isUboScriptletRule = (rule) => {
* Checks if the `rule` is AdBlock Plus snippet
*
* @param {string} rule rule text
* @returns {boolean}
* @returns {boolean} if given rule is abp rule
*/
const isAbpSnippetRule = (rule) => {
return (
Expand All @@ -99,7 +99,7 @@ const isAbpSnippetRule = (rule) => {
* Finds scriptlet by it's name
*
* @param {string} name - scriptlet name
* @returns {Function}
* @returns {Function} scriptlet function
*/
const getScriptletByName = (name) => {
const scriptlets = Object.keys(scriptletsList).map((key) => scriptletsList[key]);
Expand All @@ -118,7 +118,7 @@ const getScriptletByName = (name) => {
* Checks if the scriptlet name is valid
*
* @param {string} name - Scriptlet name
* @returns {boolean}
* @returns {boolean} if the scriptlet name is valid
*/
const isValidScriptletName = (name) => {
if (!name) {
Expand Down Expand Up @@ -272,15 +272,15 @@ const REDIRECT_RULE_TYPES = {
/**
* Parses redirect rule modifiers
*
* @param {string} rule
* @returns {Array}
* @param {string} rule rule text
* @returns {Array} list of rule modifiers
*/
const parseModifiers = (rule) => substringAfter(rule, '$').split(',');

/**
* Gets redirect resource name
*
* @param {string} rule
* @param {string} rule rule text
* @param {string} marker - specific Adg/Ubo or Abp redirect resources marker
* @returns {string} - redirect resource name
*/
Expand All @@ -296,7 +296,7 @@ const getRedirectName = (rule, marker) => {
* Discards comments and JS rules and checks if the `rule` has 'redirect' modifier.
*
* @param {string} rule - rule text
* @returns {boolean}
* @returns {boolean} if given rule is adg redirect
*/
const isAdgRedirectRule = (rule) => {
const MARKER_IN_BASE_PART_MASK = '/((?!\\$|\\,).{1})redirect((-rule)?)=(.{0,}?)\\$(popup)?/';
Expand All @@ -318,7 +318,7 @@ const isAdgRedirectRule = (rule) => {
*
* @param {string} rule - rule text
* @param {'VALID_ADG'|'ADG'|'UBO'|'ABP'} type - type of a redirect rule
* @returns {boolean}
* @returns {boolean} if the `rule` satisfies the `type`
*/
const isRedirectRuleByType = (rule, type) => {
const {
Expand Down Expand Up @@ -360,7 +360,7 @@ const isRedirectRuleByType = (rule, type) => {
* Checks if the `rule` is **valid** AdGuard redirect resource rule
*
* @param {string} rule - rule text
* @returns {boolean}
* @returns {boolean} if given rule is valid adg redirect
*/
const isValidAdgRedirectRule = (rule) => {
return isRedirectRuleByType(rule, 'VALID_ADG');
Expand Down Expand Up @@ -409,8 +409,8 @@ const isAbpRedirectCompatibleWithAdg = (rule) => {
* $script,redirect=noopvast-2.0
* $xmlhttprequest,redirect=noopvast-2.0
*
* @param {string} rule
* @returns {boolean}
* @param {string} rule rule text
* @returns {boolean} if the rule has specified content type before conversion
*/
const hasValidContentType = (rule) => {
const ruleModifiers = parseModifiers(rule);
Expand Down

0 comments on commit c49ebf4

Please sign in to comment.