UNPKG

@html-eslint/eslint-plugin

Version:
55 lines (48 loc) 985 B
/** * @import {AnyNode} from "@html-eslint/types" * @typedef {{ [key in AnyNode["type"]]?: number }} IncLevelOptions * * @typedef {(node: AnyNode) => number} GetIncreasingLevel */ class IndentLevel { /** * @param {Object} config * @param {GetIncreasingLevel} config.getIncreasingLevel */ constructor(config) { /** * @private * @member * @type {number} */ this.level = -1; /** * @private * @member * @type {number} */ this.baseLevel = 0; /** * @private * @member */ this.getInc = config.getIncreasingLevel; } /** @returns {number} */ value() { return this.level + this.baseLevel; } /** @param {AnyNode} node */ indent(node) { this.level += this.getInc(node); } /** @param {AnyNode} node */ dedent(node) { this.level -= this.getInc(node); } /** @param {number} base */ setBase(base) { this.baseLevel = base; } } module.exports = IndentLevel;