Skip to content
This repository was archived by the owner on Mar 23, 2024. It is now read-only.

Commit cca477e

Browse files
committed
disallowUnusedVariables: adapt to cst 0.1.3
1 parent 16d861e commit cca477e

File tree

2 files changed

+23
-24
lines changed

2 files changed

+23
-24
lines changed

lib/rules/disallow-unused-variables.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,25 +73,24 @@ module.exports.prototype = {
7373
} else {
7474
return false;
7575
}
76-
}
76+
};
7777

78-
var useVariable = variable.definitions.some(function checkVariableDefinition(definition) {
78+
var useVariable = variable.getDefinitions().some(function checkVariableDefinition(definition) {
7979
return parentCheck(definition.node);
8080
});
8181

82-
8382
return useVariable;
8483
}
8584

8685
function getVariablesInAllScopes(scope) {
8786
var variableList = [];
8887

8988
var iterateChildScopes = function(scope) {
90-
scope.variables.forEach(function(variable) {
89+
scope.getVariables().forEach(function(variable) {
9190
variableList.push(variable);
9291
});
9392

94-
scope.childScopes.forEach(function(childScope){
93+
scope.childScopes.forEach(function(childScope) {
9594
return iterateChildScopes(childScope);
9695
});
9796
};
@@ -115,8 +114,8 @@ module.exports.prototype = {
115114

116115
// Check if variables are used.
117116
nodesToCheck.reduce(function checkVariableReferences(acc, variable) {
118-
if (variable.references.length === 1) {
119-
variable.definitions.forEach(function addUnusedVariable(definition) {
117+
if (variable.getReferences().length === 1) {
118+
variable.getDefinitions().forEach(function addUnusedVariable(definition) {
120119
acc.push(definition.node);
121120
});
122121
}
@@ -130,7 +129,7 @@ module.exports.prototype = {
130129
_fix: function(file, error) {
131130
var node = error.element;
132131

133-
while(node.type !== 'VariableDeclaration') {
132+
while (node.type !== 'VariableDeclaration') {
134133
node = node.parentElement;
135134
}
136135

test/specs/rules/disallow-unused-variables.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -117,88 +117,88 @@ describe('rules/disallow-unused-variables', function() {
117117

118118
it('should report unused variable defined with var', function() {
119119
expect(checker.checkString('var x=1'))
120-
.to.contain.error('disallowUnusedVariables: Variable `x` is not used')
120+
.to.contain.error('disallowUnusedVariables: Variable `x` is not used');
121121
});
122122

123123
it('should report unused variable defined with let', function() {
124124
expect(checker.checkString('let x=1'))
125-
.to.contain.error('disallowUnusedVariables: Variable `x` is not used')
125+
.to.contain.error('disallowUnusedVariables: Variable `x` is not used');
126126
});
127127

128128
it('should report unused variable defined with const', function() {
129129
expect(checker.checkString('const x=1'))
130-
.to.contain.error('disallowUnusedVariables: Variable `x` is not used')
130+
.to.contain.error('disallowUnusedVariables: Variable `x` is not used');
131131
});
132132

133133
it('should report unused variable defined with var within a function declaration', function() {
134134
expect(checker.checkString('function x() { var y=1; }'))
135-
.to.contain.error('disallowUnusedVariables: Variable `y` is not used')
135+
.to.contain.error('disallowUnusedVariables: Variable `y` is not used');
136136
});
137137

138138
it('should report unused variable defined with let within a function declaration', function() {
139139
expect(checker.checkString('function x() { let y=1; }'))
140-
.to.contain.error('disallowUnusedVariables: Variable `y` is not used')
140+
.to.contain.error('disallowUnusedVariables: Variable `y` is not used');
141141
});
142142

143143
it('should report unused variable defined with const within a function declaration', function() {
144144
expect(checker.checkString('function x() { const y=1; }'))
145-
.to.contain.error('disallowUnusedVariables: Variable `y` is not used')
145+
.to.contain.error('disallowUnusedVariables: Variable `y` is not used');
146146
});
147147

148148
it('should report unused variable defined with var within a arrow function expression', function() {
149149
expect(checker.checkString('() => { var x=1; }'))
150-
.to.contain.error('disallowUnusedVariables: Variable `x` is not used')
150+
.to.contain.error('disallowUnusedVariables: Variable `x` is not used');
151151
});
152152

153153
it('should report unused variable defined with let within a arrow function expression', function() {
154154
expect(checker.checkString('() => { let x=1; }'))
155-
.to.contain.error('disallowUnusedVariables: Variable `x` is not used')
155+
.to.contain.error('disallowUnusedVariables: Variable `x` is not used');
156156
});
157157

158158
it('should report unused variable defined with const within a arrow function expression', function() {
159159
expect(checker.checkString('() => { const x=1; }'))
160-
.to.contain.error('disallowUnusedVariables: Variable `x` is not used')
160+
.to.contain.error('disallowUnusedVariables: Variable `x` is not used');
161161
});
162162

163163
it('should report unused variable defined with var within a function expression', function() {
164164
expect(checker.checkString('(function() { var x=1; })'))
165-
.to.contain.error('disallowUnusedVariables: Variable `x` is not used')
165+
.to.contain.error('disallowUnusedVariables: Variable `x` is not used');
166166
});
167167

168168
it('should report unused variable defined with var within a class', function() {
169169
expect(checker.checkString('class P { test() { var x=1; } }'))
170-
.to.contain.error('disallowUnusedVariables: Variable `x` is not used')
170+
.to.contain.error('disallowUnusedVariables: Variable `x` is not used');
171171
});
172172

173173
it('should report unused variable defined with let within a class', function() {
174174
expect(checker.checkString('class P { test() { let x=1; } }'))
175-
.to.contain.error('disallowUnusedVariables: Variable `x` is not used')
175+
.to.contain.error('disallowUnusedVariables: Variable `x` is not used');
176176
});
177177

178178
it('should report unused variable defined with const within a class', function() {
179179
expect(checker.checkString('class P { test() { const x=1; } }'))
180-
.to.contain.error('disallowUnusedVariables: Variable `x` is not used')
180+
.to.contain.error('disallowUnusedVariables: Variable `x` is not used');
181181
});
182182

183183
it('should report unused variable defined with var for a ObjectPattern', function() {
184184
expect(checker.checkString('var { x, y } = 1;'))
185185
.to.contain.error('disallowUnusedVariables: Variable `x` is not used')
186186
.to.contain.error('disallowUnusedVariables: Variable `y` is not used')
187-
.have.error.count.equal(2)
187+
.have.error.count.equal(2);
188188
});
189189

190190
it('should report unused variable defined with let for a ObjectPattern', function() {
191191
expect(checker.checkString('let { x, y } = 1;'))
192192
.to.contain.error('disallowUnusedVariables: Variable `x` is not used')
193193
.to.contain.error('disallowUnusedVariables: Variable `y` is not used')
194-
.have.error.count.equal(2)
194+
.have.error.count.equal(2);
195195
});
196196

197197
it('should report unused variable defined with const for a ObjectPattern', function() {
198198
expect(checker.checkString('const { x, y } = 1;'))
199199
.to.contain.error('disallowUnusedVariables: Variable `x` is not used')
200200
.to.contain.error('disallowUnusedVariables: Variable `y` is not used')
201-
.have.error.count.equal(2)
201+
.have.error.count.equal(2);
202202
});
203203

204204
reportAndFix({

0 commit comments

Comments
 (0)