Gathering detailed insights and metrics for @droppedcode/eslint-plugin-jasmine-memoryleak-linter
Gathering detailed insights and metrics for @droppedcode/eslint-plugin-jasmine-memoryleak-linter
Gathering detailed insights and metrics for @droppedcode/eslint-plugin-jasmine-memoryleak-linter
Gathering detailed insights and metrics for @droppedcode/eslint-plugin-jasmine-memoryleak-linter
ESLint plugin to find and fix jasmine memory leaks
npm install @droppedcode/eslint-plugin-jasmine-memoryleak-linter
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
1 Stars
20 Commits
1 Watching
1 Branches
1 Contributors
Updated on 17 Nov 2024
TypeScript (100%)
Cumulative downloads
Total Downloads
Last day
220.3%
221
Compared to previous day
Last week
9.6%
642
Compared to previous week
Last month
-20.6%
3,710
Compared to previous month
Last year
124.2%
51,114
Compared to previous year
1
17
This plugin for eslint looks for errors with the usage of jasmine (or mocha but that is just a coincidence based on the same naming conventions).
To configure the ESLint use the usual way:
1{ 2 // ... 3 "plugins": [ 4 // ... 5 "@droppedcode/eslint-plugin-jasmine-memoryleak-linter" 6 ], 7 "rules": { 8 // ... 9 "@droppedcode/jasmine-memoryleak-linter/describe-declarations": "error", 10 "@droppedcode/jasmine-memoryleak-linter/no-cleanup-before-each-rule": "error", 11 "@droppedcode/jasmine-memoryleak-linter/no-cleanup-before-all-rule": "error" 12 } 13}
or use predefined configuration
1{ 2 // ... 3 "extends": [ 4 // ... 5 "@droppedcode/eslint-plugin-jasmine-memoryleak-linter/recommended" 6 ] 7}
All rules has a built in fix, but usually gives multiple suggestions to how to solve the issue.
Looks for cases where variables are declared and initialized within a "describe" method:
1describe('test-describe-let', () => { 2 let a = {}; // This will trigger it 3 4 it('test', () => { 5 // use a... 6 }); 7});
This can be fixed in multiple ways:
Moves the declaration logic to the "it" blocks. This will cause the variable to be local and GC will clean it up.
1describe('test-describe-let', () => { 2 it('test', () => { 3 let a = {}; 4 // use a... 5 }); 6});
(This is the default fix.)
1describe('test-describe-let', () => { 2 let a; 3 4 beforeEach(() => { 5 a = {}; 6 }); 7 8 afterEach(() => { 9 a = undefined; 10 }); 11 12 it('test', () => { 13 // use a... 14 }); 15});
1describe('test-describe-let', () => { 2 let a; 3 4 beforeAll(() => { 5 a = {}; 6 }); 7 8 afterAll(() => { 9 a = undefined; 10 }); 11 12 it('test', () => { 13 // use a... 14 }); 15});
Looks for cases where variables are declared and initialized within a "describe" method, but used only for initialization in an other describe:
1describe('test-describe-let', () => { 2 let a = [1, 2]; // This will trigger it 3 4 describe('inner', () => { 5 a.forEach(() => {}); 6 }); 7});
1describe('test-describe-let', () => { 2 describe('inner', () => { 3 let a = [1, 2]; 4 5 a.forEach(() => {}); 6 }); 7});
1export type InDescribeRuleOptions = { 2 /** Names of the functions that the rule is looking for. */ 3 functionNames: string[]; 4 /** Names of the functions that can initialize values before all tests. */ 5 initializationAllFunctionNames: string[]; 6 /** Names of the functions that can initialize values before each test. */ 7 initializationEachFunctionNames: string[]; 8 /** Names of the functions that can unreference values before all tests. */ 9 unreferenceAllFunctionNames: string[]; 10 /** Names of the functions that can unreference values before each test. */ 11 unreferenceEachFunctionNames: string[]; 12 /** Names of the functions that can use the values. */ 13 testFunctionNames: string[]; 14 /** Prefer using initialization in all function. */ 15 preferAll: boolean; 16};
The default options are a merge of jasmine and mocha naming convention, but there are separate configurations if that is preferred.
1export const defaultJasmineInDescribeRuleOptions: InDescribeRuleOptions = { 2 functionNames: ['describe', 'fdescribe', 'xdescribe'], 3 initializationEachFunctionNames: ['beforeEach'], 4 initializationAllFunctionNames: ['beforeAll'], 5 unreferenceEachFunctionNames: ['afterEach'], 6 unreferenceAllFunctionNames: ['afterAll'], 7 testFunctionNames: ['it', 'fit', 'xit'], 8 preferAll: false, 9}; 10 11export const defaultMochaInDescribeRuleOptions: InDescribeRuleOptions = { 12 functionNames: ['describe', 'fdescribe', 'xdescribe'], 13 initializationEachFunctionNames: ['beforeEach'], 14 initializationAllFunctionNames: ['before'], 15 unreferenceEachFunctionNames: ['afterEach'], 16 unreferenceAllFunctionNames: ['after'], 17 testFunctionNames: ['it', 'test', 'fit', 'xit'], 18 preferAll: false, 19}; 20 21export const defaultInDescribeRuleOptions = { 22 functionNames: ['describe', 'fdescribe', 'xdescribe'], 23 initializationEachFunctionNames: ['beforeEach'], 24 initializationAllFunctionNames: ['beforeAll', 'before'], 25 unreferenceEachFunctionNames: ['afterEach'], 26 unreferenceAllFunctionNames: ['afterAll', 'after'], 27 testFunctionNames: ['it', 'test', 'fit', 'xit'], 28 preferAll: false, 29};
Looks for cases when assignment to a variable happens in a describe but not within a declaration.
1describe('test-describe-let', () => { 2 let a; 3 a = {}; // This will trigger it 4 5 it('test', () => { 6 // use a... 7 }); 8});
(This is the default fix.)
1describe('test-describe-let', () => { 2 let a; 3 4 beforeEach(() => { 5 a = {}; 6 }); 7 8 afterEach(() => { 9 a = undefined; 10 }); 11 12 it('test', () => { 13 // use a... 14 }); 15});
1describe('test-describe-let', () => { 2 let a; 3 4 beforeAll(() => { 5 a = {}; 6 }); 7 8 afterAll(() => { 9 a = undefined; 10 }); 11 12 it('test', () => { 13 // use a... 14 }); 15});
Same as declaration-in-describe rule.
Looks for cases when we assign a value to a variable in a beforeEach call, but there is no or the last assignment is not a dereference.
If we dereference it in an afterAll, this rule will still trigger (initialization and cleanup should happen in the same level).
1describe('test-describe-let', () => { 2 let a; 3 4 beforeEach(() => { 5 a = {}; // This will trigger it 6 }); 7});
The fix for this will unreference the variable in a afterEach call.
1describe('test-describe-let', () => { 2 let a; 3 4 beforeEach(() => { 5 a = {}; 6 }); 7 8 afterEach(() => { 9 a = undefined; 10 }); 11});
1export const defaultNoCleanupEachOptions = { 2 initializationFunctionNames: ['beforeEach'], 3 unreferenceFunctionNames: ['afterEach'] 4}; 5 6There are mocha and jasmine variant of the options.
Looks for cases when we assign a value to a variable in a beforeAll call, but there is no or the last assignment is not a dereference.
If we dereference it in an afterEach, this rule will still trigger (initialization and cleanup should happen in the same level).
1describe('test-describe-let', () => { 2 let a; 3 4 beforeAll(() => { 5 a = {}; // This will trigger it 6 }); 7});
The fix for this will unreference the variable in a afterEach call.
1describe('test-describe-let', () => { 2 let a; 3 4 beforeAll(() => { 5 a = {}; 6 }); 7 8 afterAll(() => { 9 a = undefined; 10 }); 11});
1export const defaultNoCleanupAllOptions = { 2 initializationFunctionNames: ['beforeAll', 'before'], 3 unreferenceFunctionNames: ['afterAll', 'after'] 4}; 5 6There are mocha and jasmine variant of the options.
Looks for cases when we assign a value to a variable in a beforeAll call, but there is no or the last assignment is not a dereference.
If we dereference it in an afterEach, this rule will still trigger (initialization and cleanup should happen in the same level).
1describe('test-describe-let', () => { 2 let a; 3 4 beforeAll(() => { 5 a = {}; // This will trigger it 6 }); 7});
The fix for this will unreference the variable in a afterEach call.
1describe('test-describe-let', () => { 2 let a; 3 4 beforeAll(() => { 5 a = {}; 6 }); 7 8 afterAll(() => { 9 a = undefined; 10 }); 11});
1export const defaultNoCleanupTestOptions = { 2 initializationFunctionNames: ['it', 'fit', 'xit', 'test'], 3 unreferenceFunctionNames: ['it', 'afterEach', 'afterAll', 'after'], 4}; 5 6There are mocha and jasmine variant of the options. 7
npm test
The samples are a configured mini project that uses only these rules, so you can see it in action. To try it out open the samples folder, do not run it from the main folder, because ESLint will have false results.
var
" declarations in certain situations (when it is not used like a "let
") can break some logics.describe.only
.No vulnerabilities found.
No security vulnerabilities found.