]> git.proxmox.com Git - pve-eslint.git/blob - eslint/lib/linter/code-path-analysis/id-generator.js
import 8.3.0 source
[pve-eslint.git] / eslint / lib / linter / code-path-analysis / id-generator.js
1 /**
2 * @fileoverview A class of identifiers generator for code path segments.
3 *
4 * Each rule uses the identifier of code path segments to store additional
5 * information of the code path.
6 *
7 * @author Toru Nagashima
8 */
9
10 "use strict";
11
12 //------------------------------------------------------------------------------
13 // Public Interface
14 //------------------------------------------------------------------------------
15
16 /**
17 * A generator for unique ids.
18 */
19 class IdGenerator {
20
21 /**
22 * @param {string} prefix Optional. A prefix of generated ids.
23 */
24 constructor(prefix) {
25 this.prefix = String(prefix);
26 this.n = 0;
27 }
28
29 /**
30 * Generates id.
31 * @returns {string} A generated id.
32 */
33 next() {
34 this.n = 1 + this.n | 0;
35
36 /* istanbul ignore if */
37 if (this.n < 0) {
38 this.n = 1;
39 }
40
41 return this.prefix + this.n;
42 }
43 }
44
45 module.exports = IdGenerator;