Skip to content

Commit

Permalink
config and apply check-types
Browse files Browse the repository at this point in the history
  • Loading branch information
stanislav-atr committed Dec 30, 2022
1 parent 8a17e2d commit 9edacb0
Show file tree
Hide file tree
Showing 31 changed files with 69 additions and 62 deletions.
7 changes: 7 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,11 @@ module.exports = {
'jsdoc/require-param-description': 0,
'jsdoc/require-returns-description': 0,
},
settings: {
jsdoc: {
preferredTypes: {
object: 'Object',
},
},
},
};
4 changes: 2 additions & 2 deletions scripts/build-compatibility-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ const WIKI_COMPATIBILITY_TABLE_PATH = path.resolve(
);

/**
* @typedef {object} CompatibilityItem
* @typedef {Object} CompatibilityItem
* @property {string} adg AdGuard name
* @property {string} abp Adblock Plus name
* @property {string} ubo uBlock name
*/

/**
* @typedef {object} CompatibilityData
* @typedef {Object} CompatibilityData
* @property {CompatibilityItem[]} scriptlets list of scriptlets compatibility items
* @property {CompatibilityItem[]} redirects list of redirects compatibility items
*/
Expand Down
4 changes: 2 additions & 2 deletions scripts/build-docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const aboutTrustedScriptletsPath = path.resolve(
/**
* Collects required comments from files
*
* @returns {object} describing object for scriptlets and redirects
* @returns {Object} describing object for scriptlets and redirects
*/
const manageDataFromFiles = () => {
const dataFromScriptletsFiles = getDataFromFiles(
Expand Down Expand Up @@ -87,7 +87,7 @@ const manageDataFromFiles = () => {
*/

/**
* @typedef {object} MarkdownData
* @typedef {Object} MarkdownData
* @property {string} list table of content
* @property {string} body main content which
*/
Expand Down
2 changes: 1 addition & 1 deletion scripts/build-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const TEST_FILE_NAME_MARKER = '.test.js';
* @param {string} fileName test file name
* @param {string} dirPath resolved directory path
* @param {string} subDir subdirectory with test files
* @returns {object} rollup config
* @returns {Object} rollup config
*/
const getTestConfig = (fileName, dirPath, subDir) => {
if (!fs.existsSync(TESTS_DIST)) {
Expand Down
4 changes: 2 additions & 2 deletions scripts/check-sources-updates.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const areArraysOfStringsEqual = (arr1, arr2) => {
/**
* Returns parsed compatibility table
*
* @returns {object}
* @returns {Object}
*/
const getCompatibilityTable = () => {
const rawData = fs.readFileSync(COMPATIBILITY_TABLE_DATA_PATH);
Expand Down Expand Up @@ -64,7 +64,7 @@ const getRedirectsFromTable = (platform) => {
};

/**
* @typedef {object} Diff
* @typedef {Object} Diff
* @property {string[]} added added content
* @property {string[]} removed removed content
*/
Expand Down
4 changes: 2 additions & 2 deletions scripts/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const getFilesList = (relativeDirPath) => {
};

/**
* @typedef {object} CommentTag
* @typedef {Object} CommentTag
* @property {string} type tag name
* @property {string} string text following the tag
*/
Expand Down Expand Up @@ -77,7 +77,7 @@ Please add one OR edit the list of NON_SCRIPTLETS_FILES / NON_REDIRECTS_FILES.`)
};

/**
* @typedef {object} DescribingCommentData
* @typedef {Object} DescribingCommentData
*
* Collected data from jsdoc-type comment for every scriptlet or redirect.
* @property {string} type parsed instance tag:
Expand Down
6 changes: 3 additions & 3 deletions src/helpers/converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const getSentences = (str) => {
* Replaces string with data by placeholders
*
* @param {string} str string with placeholders
* @param {object} data - where keys are placeholders names
* @param {Object} data - where keys are placeholders names
* @returns {string} string filled with data
*/
const replacePlaceholders = (str, data) => {
Expand Down Expand Up @@ -362,9 +362,9 @@ export const isValidScriptletRule = (input) => {
* Gets index and redirect resource marker from UBO/ADG modifiers array
*
* @param {string[]} modifiers rule modifiers
* @param {object} redirectsData validator.REDIRECT_RULE_TYPES.(UBO|ADG)
* @param {Object} redirectsData validator.REDIRECT_RULE_TYPES.(UBO|ADG)
* @param {string} rule rule string
* @returns {object} { index, marker }
* @returns {Object} { index, marker }
*/
const getMarkerData = (modifiers, redirectsData, rule) => {
let marker;
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/cookie-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export const getLimitedCookieValue = (value) => {
* Parses cookie string into object
*
* @param {string} cookieString string that conforms to document.cookie format
* @returns {object} key:value object that corresponds with incoming cookies keys and values
* @returns {Object} key:value object that corresponds with incoming cookies keys and values
*/
export const parseCookieString = (cookieString) => {
const COOKIE_DELIMITER = '=';
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/get-descriptor-addon.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { randomId } from './random-id';
* https://github.com/AdguardTeam/Scriptlets/issues/226
* https://github.com/AdguardTeam/Scriptlets/issues/232
*
* @returns {object} descriptor addon
* @returns {Object} descriptor addon
*/
export function getDescriptorAddon() {
return {
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/get-property-in-chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { isEmptyObject } from './object-utils';

/**
* @typedef ChainInfo
* @property {object} base current chain base
* @property {Object} base current chain base
* @property {string} prop current chain prop
* @property {string} [chain] string representation
*/
Expand All @@ -14,7 +14,7 @@ import { isEmptyObject } from './object-utils';
* defines this property as 'undefined'
* and returns base, property name and remaining part of property chain
*
* @param {object} base object that owns chain
* @param {Object} base object that owns chain
* @param {string} chain chain of owner properties
* @returns {ChainInfo} chain info object
*/
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/get-wildcard-property-in-chain.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @typedef ChainInfo
* @property {object} base current chain base
* @property {Object} base current chain base
* @property {string} prop current chain prop
* @property {string} [chain] string representation
*/
Expand All @@ -10,7 +10,7 @@
* Similar to getPropertyInChain but upgraded for json-prune:
* handle wildcard properties and does not define nonexistent base property as 'undefined'
*
* @param {object} base object that owns chain
* @param {Object} base object that owns chain
* @param {string} chain chain of owner properties
* @param {boolean} [lookThrough=false]
* should the method look through it's props in order to wildcard
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/hit.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* Hit used only for debug purposes now
*
* @param {object} source scriptlet properties
* @param {Object} source scriptlet properties
* use LOG_MARKER = 'log: ' at the start of a message
* for logging scriptlets
*/
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/injector.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function addCall(scriptlet, code) {
* function noeval(source) { alert(source); }
* noeval.apply(this, args);
* )({"args": ["aaa", "bbb"], "name":"noeval"}, ["aaa", "bbb"])`
* @param {object} source - object with scriptlet properties
* @param {Object} source - object with scriptlet properties
* @param {string} code - scriptlet source code with dependencies
* @param {boolean} redirect if function is redirect
* @returns {string} full scriptlet code
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/log-message.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* is not a part of scriptlet's functionality, eg on invalid input,
* and use 'forced' argument otherwise.
*
* @param {object} source required, scriptlet properties
* @param {Object} source required, scriptlet properties
* @param {string} message required, message to log
* @param {boolean} [forced=false] to log message unconditionally
*/
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/match-request-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import { logMessage } from './log-message';
* This is used by prevent-xhr, prevent-fetch, trusted-replace-xhr-response
* and trusted-replace-fetch-response scriptlets
*
* @param {object} source scriptlet properties
* @param {Object} source scriptlet properties
* @param {string} propsToMatch string of space-separated request properties to match
* @param {object} requestData object with standard properties of fetch/xhr like url, method etc
* @param {Object} requestData object with standard properties of fetch/xhr like url, method etc
* @returns {boolean} if request properties match
*/
export const matchRequestProps = (source, propsToMatch, requestData) => {
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/noop-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const noopArray = () => [];
/**
* Function returns empty object
*
* @returns {object} empty object
* @returns {Object} empty object
*/
export const noopObject = () => ({});

Expand Down
12 changes: 6 additions & 6 deletions src/helpers/object-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Object.entries() polyfill because it is not supported by IE
* https://caniuse.com/?search=Object.entries
*
* @param {object} object arbitrary object
* @param {Object} object arbitrary object
* @returns {Array} array of pairs
*/
export const getObjectEntries = (object) => {
Expand All @@ -19,7 +19,7 @@ export const getObjectEntries = (object) => {
* https://caniuse.com/?search=Object.fromEntries
*
* @param {Array} entries - array of pairs
* @returns {object} result object
* @returns {Object} result object
*/
export const getObjectFromEntries = (entries) => {
const output = entries
Expand All @@ -35,15 +35,15 @@ export const getObjectFromEntries = (entries) => {
/**
* Checks whether the obj is an empty object
*
* @param {object} obj arbitrary object
* @param {Object} obj arbitrary object
* @returns {boolean} if object is empty
*/
export const isEmptyObject = (obj) => Object.keys(obj).length === 0 && !obj.prototype;

/**
* Safely retrieve property descriptor
*
* @param {object} obj target object
* @param {Object} obj target object
* @param {string} prop target property
* @returns {object|null} descriptor or null if it's not available or non-configurable
*/
Expand All @@ -58,9 +58,9 @@ export const safeGetDescriptor = (obj, prop) => {
/**
* Set getter and setter to property if it's configurable
*
* @param {object} object target object with property
* @param {Object} object target object with property
* @param {string} property property name
* @param {object} descriptor contains getter and setter functions
* @param {Object} descriptor contains getter and setter functions
* @returns {boolean} is operation successful
*/
export function setPropertyAccess(object, property, descriptor) {
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/open-shadow-dom-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const findHostElements = (rootElement) => {
*/

/**
* @typedef {object} PierceData
* @typedef {Object} PierceData
* @property {HTMLElement[]} targets found elements that match the specified selector
* @property {HTMLElement[]} innerHosts inner shadow-dom hosts
*/
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/parse-flags.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @typedef {object} FlagsData object that holds info about valid flags
* @typedef {Object} FlagsData object that holds info about valid flags
* and provides method for easy access
* @property {string} ASAP asap flag string
* @property {string} COMPLETE complete flag string
Expand Down
14 changes: 7 additions & 7 deletions src/helpers/parse-rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Iterate over iterable argument and evaluate current state with transitions
*
* @param {Array|string} iterable rule or list or rules
* @param {object} transitions transtion functions
* @param {Object} transitions transtion functions
* @param {string} init first transition name
* @param {any} args arguments which should be passed to transition functions
* @returns {string} state
Expand All @@ -23,7 +23,7 @@ export const ADG_SCRIPTLET_MASK = '#//scriptlet';
/**
* Helper to accumulate an array of strings char by char
*
* @returns {object} object with helper methods
* @returns {Object} object with helper methods
*/
const wordSaver = () => {
let str = '';
Expand Down Expand Up @@ -72,8 +72,8 @@ export const parseRule = (ruleText) => {
*
* @param {string} rule rule string
* @param {number} index index
* @param {object} Object helper object
* @param {object} Object.sep contains prop symb with current separator char
* @param {Object} Object helper object
* @param {Object} Object.sep contains prop symb with current separator char
* @throws {string} throws if given rule is not a scriptlet
* @returns {string} transition
*/
Expand Down Expand Up @@ -111,9 +111,9 @@ export const parseRule = (ruleText) => {
*
* @param {string} rule rule string
* @param {number} index index
* @param {object} Object helper object
* @param {object} Object.sep contains prop `symb` with current separator char
* @param {object} Object.saver helper which allow to save strings by car by char
* @param {Object} Object helper object
* @param {Object} Object.sep contains prop `symb` with current separator char
* @param {Object} Object.saver helper which allow to save strings by car by char
* @returns {void}
*/
const param = (rule, index, { saver, sep }) => {
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/prevent-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const parseRawDelay = (delay) => {
* by given parameters 'matchCallback' and 'matchDelay'.
* Used for prevent-setTimeout and prevent-setInterval.
*
* @param {object} preventData set of data to determine if scriptlet should match
* @param {Object} preventData set of data to determine if scriptlet should match
* @param {Function} preventData.callback method's callback arg
* @param {any} preventData.delay method's delay arg
* @param {string} preventData.matchCallback scriptlets's callback arg
Expand Down
14 changes: 7 additions & 7 deletions src/helpers/request-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const getRequestProps = () => [
* Collects Request options to object
*
* @param {Request} request Request instance to collect properties from
* @returns {object} data object
* @returns {Object} data object
*/
export const getRequestData = (request) => {
const requestInitOptions = getRequestProps();
Expand All @@ -44,7 +44,7 @@ export const getRequestData = (request) => {
* Collects fetch args to object
*
* @param {*} args fetch args
* @returns {object} data object
* @returns {Object} data object
*/
export const getFetchData = (args) => {
const fetchPropsObj = {};
Expand Down Expand Up @@ -79,7 +79,7 @@ export const getFetchData = (args) => {
* @param {string} async request async prop
* @param {string} user request user prop
* @param {string} password request password prop
* @returns {object} aggregated request data
* @returns {Object} aggregated request data
*/
export const getXhrData = (method, url, async, user, password) => {
return {
Expand All @@ -96,7 +96,7 @@ export const getXhrData = (method, url, async, user, password) => {
* used for prevent-fetch and prevent-xhr
*
* @param {string} propsToMatchStr string of space-separated request properties to match
* @returns {object} object where 'key' is prop name and 'value' is prop value
* @returns {Object} object where 'key' is prop name and 'value' is prop value
*/
export const parseMatchProps = (propsToMatchStr) => {
const PROPS_DIVIDER = ' ';
Expand Down Expand Up @@ -129,7 +129,7 @@ export const parseMatchProps = (propsToMatchStr) => {
/**
* Validates parsed data values
*
* @param {object} data request data
* @param {Object} data request data
* @returns {boolean} if data is valid
*/
export const validateParsedData = (data) => {
Expand All @@ -140,8 +140,8 @@ export const validateParsedData = (data) => {
/**
* Converts valid parsed data to data obj for further matching
*
* @param {object} data parsed request data
* @returns {object} data obj ready for matching
* @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/storage-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { logMessage } from './log-message';
/**
* Sets item to a specified storage, if storage isn't full.
*
* @param {object} source scriptlet's configuration
* @param {Object} source scriptlet's configuration
* @param {Storage} storage storage instance to set item into
* @param {string} key storage key
* @param {string} value staroge value
Expand Down
Loading

0 comments on commit 9edacb0

Please sign in to comment.