Skip to content

Commit 28929cb

Browse files
authoredSep 11, 2017
Chore: remove Linter#reset (refs #9161) (#9268)
1 parent abc8634 commit 28929cb

File tree

10 files changed

+5
-82
lines changed

10 files changed

+5
-82
lines changed
 

‎docs/developer-guide/nodejs-api.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,16 @@ var linter = new Linter();
6060

6161
### Linter#verify
6262

63-
The most important method on `Linter` is `verify()`, which initiates linting of the given text. This method accepts four arguments:
63+
The most important method on `Linter` is `verify()`, which initiates linting of the given text. This method accepts three arguments:
6464

6565
* `code` - the source code to lint (a string or instance of `SourceCode`).
6666
* `config` - a configuration object that has been processed and normalized by CLIEngine using eslintrc files and/or other configuration arguments.
6767
* **Note**: If you want to lint text and have your configuration be read and processed, use CLIEngine's [`executeOnFiles`](#executeonfiles) or [`executeOnText`](#executeontext) instead.
68-
* `optionsOrFilename` - (optional) Additional options for this run or a string representing the filename to associate with the code being linted.
68+
* `options` - (optional) Additional options for this run.
6969
* `filename` - (optional) the filename to associate with the source code.
70-
* `saveState` - (optional) see below. This will override any value passed as the fourth argument if an options object is used here instead of the filename.
7170
* `allowInlineConfig` - (optional) set to `false` to disable inline comments from changing eslint rules.
72-
* `saveState` - (optional) set to true to maintain the internal state of `linter` after linting (mostly used for testing purposes)
71+
72+
If the third argument is a string, it is interpreted as the `filename`.
7373

7474
You can call `verify()` like this:
7575

‎lib/cli-engine.js

-4
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,6 @@ function calculateStatsPerRun(results) {
142142
* @private
143143
*/
144144
function processText(text, configHelper, filename, fix, allowInlineConfig, linter) {
145-
146-
// clear all existing settings for a new file
147-
linter.reset();
148-
149145
let filePath,
150146
messages,
151147
fileExtension,

‎lib/linter.js

+1-16
Original file line numberDiff line numberDiff line change
@@ -709,14 +709,6 @@ module.exports = class Linter {
709709
this.environments = new Environments();
710710
}
711711

712-
/**
713-
* Resets the internal state of the object.
714-
* @returns {void}
715-
*/
716-
reset() {
717-
this.sourceCode = null;
718-
}
719-
720712
/**
721713
* Configuration object for the `verify` API. A JS representation of the eslintrc files.
722714
* @typedef {Object} ESLintConfig
@@ -735,13 +727,11 @@ module.exports = class Linter {
735727
* @param {(string|Object)} [filenameOrOptions] The optional filename of the file being checked.
736728
* If this is not set, the filename will default to '<input>' in the rule context. If
737729
* an object, then it has "filename", "saveState", and "allowInlineConfig" properties.
738-
* @param {boolean} [saveState] Indicates if the state from the last run should be saved.
739-
* Mostly useful for testing purposes.
740730
* @param {boolean} [filenameOrOptions.allowInlineConfig] Allow/disallow inline comments' ability to change config once it is set. Defaults to true if not supplied.
741731
* Useful if you want to validate JS without comments overriding rules.
742732
* @returns {Object[]} The results as an array of messages or null if no messages.
743733
*/
744-
verify(textOrSourceCode, config, filenameOrOptions, saveState) {
734+
verify(textOrSourceCode, config, filenameOrOptions) {
745735
let text,
746736
parserServices,
747737
allowInlineConfig,
@@ -751,17 +741,12 @@ module.exports = class Linter {
751741
if (typeof filenameOrOptions === "object") {
752742
providedFilename = filenameOrOptions.filename;
753743
allowInlineConfig = filenameOrOptions.allowInlineConfig;
754-
saveState = filenameOrOptions.saveState;
755744
} else {
756745
providedFilename = filenameOrOptions;
757746
}
758747

759748
const filename = typeof providedFilename === "string" ? providedFilename : "<input>";
760749

761-
if (!saveState) {
762-
this.reset();
763-
}
764-
765750
if (typeof textOrSourceCode === "string") {
766751
this.sourceCode = null;
767752
text = textOrSourceCode;

‎lib/testers/rule-tester.js

-2
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,6 @@ class RuleTester {
332332
* The goal is to check whether or not AST was modified when
333333
* running the rule under test.
334334
*/
335-
linter.reset();
336-
337335
linter.defineRule("rule-tester/validate-ast", () => ({
338336
Program(node) {
339337
beforeAST = cloneDeeplyExcludesParent(node);

‎tests/lib/ast-utils.js

-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ describe("ast-utils", () => {
5656
`Expected ${func.toString()} to be called at least once but it was not called`
5757
);
5858
});
59-
60-
linter.reset();
6159
});
6260

6361
describe("isTokenOnSameLine", () => {

‎tests/lib/code-path-analysis/code-path-analyzer.js

-5
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,6 @@ function getExpectedDotArrows(source) {
5454
//------------------------------------------------------------------------------
5555

5656
describe("CodePathAnalyzer", () => {
57-
58-
afterEach(() => {
59-
linter.reset();
60-
});
61-
6257
EventGeneratorTester.testEventGeneratorInterface(
6358
new CodePathAnalyzer(new NodeEventGenerator(new EventEmitter()))
6459
);

‎tests/lib/code-path-analysis/code-path.js

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ const linter = new Linter();
2626
function parseCodePaths(code) {
2727
const retv = [];
2828

29-
linter.reset();
3029
linter.defineRule("test", () => ({
3130
onCodePathStart(codePath) {
3231
retv.push(codePath);

‎tests/lib/linter.js

-42
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ describe("Linter", () => {
171171
const code = TEST_CODE;
172172

173173
it("should retrieve SourceCode object after reset", () => {
174-
linter.reset();
175174
linter.verify(code, {}, filename, true);
176175

177176
const sourceCode = linter.getSourceCode();
@@ -182,7 +181,6 @@ describe("Linter", () => {
182181
});
183182

184183
it("should retrieve SourceCode object without reset", () => {
185-
linter.reset();
186184
linter.verify(code, {}, filename);
187185

188186
const sourceCode = linter.getSourceCode();
@@ -860,7 +858,6 @@ describe("Linter", () => {
860858
const code = "test-rule";
861859

862860
it("should pass settings to all rules", () => {
863-
linter.reset();
864861
linter.defineRule(code, context => ({
865862
Literal(node) {
866863
context.report(node, context.settings.info);
@@ -878,7 +875,6 @@ describe("Linter", () => {
878875
});
879876

880877
it("should not have any settings if they were not passed in", () => {
881-
linter.reset();
882878
linter.defineRule(code, context => ({
883879
Literal(node) {
884880
if (Object.getOwnPropertyNames(context.settings).length !== 0) {
@@ -908,7 +904,6 @@ describe("Linter", () => {
908904
}
909905
};
910906

911-
linter.reset();
912907
linter.defineRule("test-rule", sandbox.mock().withArgs(
913908
sinon.match({ parserOptions })
914909
).returns({}));
@@ -922,7 +917,6 @@ describe("Linter", () => {
922917

923918
const parserOptions = {};
924919

925-
linter.reset();
926920
linter.defineRule("test-rule", sandbox.mock().withArgs(
927921
sinon.match({ parserOptions })
928922
).returns({}));
@@ -942,7 +936,6 @@ describe("Linter", () => {
942936

943937
const alternateParser = "esprima-fb";
944938

945-
linter.reset();
946939
linter.defineRule("test-rule", sandbox.mock().withArgs(
947940
sinon.match({ parserPath: alternateParser })
948941
).returns({}));
@@ -955,9 +948,6 @@ describe("Linter", () => {
955948
it("should use parseForESLint() in custom parser when custom parser is specified", () => {
956949

957950
const alternateParser = path.resolve(__dirname, "../fixtures/parsers/enhanced-parser.js");
958-
959-
linter.reset();
960-
961951
const config = { rules: {}, parser: alternateParser };
962952
const messages = linter.verify("0", config, filename);
963953

@@ -968,7 +958,6 @@ describe("Linter", () => {
968958

969959
const alternateParser = path.resolve(__dirname, "../fixtures/parsers/enhanced-parser.js");
970960

971-
linter.reset();
972961
linter.defineRule("test-service-rule", context => ({
973962
Literal(node) {
974963
context.report({
@@ -1007,7 +996,6 @@ describe("Linter", () => {
1007996
config = { rules: {} };
1008997

1009998
config.rules[rule] = 1;
1010-
linter.reset();
1011999

10121000
const messages = linter.verify(code, config, filename, true);
10131001

@@ -1020,7 +1008,6 @@ describe("Linter", () => {
10201008
config = { rules: {} };
10211009

10221010
config.rules[rule] = "warn";
1023-
linter.reset();
10241011

10251012
const messages = linter.verify(code, config, filename, true);
10261013

@@ -1034,7 +1021,6 @@ describe("Linter", () => {
10341021
config = { rules: {} };
10351022

10361023
config.rules[rule] = [1];
1037-
linter.reset();
10381024

10391025
const messages = linter.verify(code, config, filename, true);
10401026

@@ -1047,7 +1033,6 @@ describe("Linter", () => {
10471033
config = { rules: {} };
10481034

10491035
config.rules[rule] = ["warn"];
1050-
linter.reset();
10511036

10521037
const messages = linter.verify(code, config, filename, true);
10531038

@@ -1061,7 +1046,6 @@ describe("Linter", () => {
10611046
config = { rules: {} };
10621047

10631048
config.rules[rule] = "1";
1064-
linter.reset();
10651049

10661050
const messages = linter.verify(code, config, filename, true);
10671051

@@ -1070,8 +1054,6 @@ describe("Linter", () => {
10701054

10711055
it("should process empty config", () => {
10721056
const config = {};
1073-
1074-
linter.reset();
10751057
const messages = linter.verify(code, config, filename, true);
10761058

10771059
assert.equal(messages.length, 0);
@@ -1415,7 +1397,6 @@ describe("Linter", () => {
14151397
const code = "new-rule";
14161398

14171399
it("can add a rule dynamically", () => {
1418-
linter.reset();
14191400
linter.defineRule(code, context => ({
14201401
Literal(node) {
14211402
context.report(node, "message");
@@ -1438,7 +1419,6 @@ describe("Linter", () => {
14381419
const code = ["new-rule-0", "new-rule-1"];
14391420

14401421
it("can add multiple rules dynamically", () => {
1441-
linter.reset();
14421422
const config = { rules: {} };
14431423
const newRules = {};
14441424

@@ -1470,7 +1450,6 @@ describe("Linter", () => {
14701450
const code = "filename-rule";
14711451

14721452
it("has access to the filename", () => {
1473-
linter.reset();
14741453
linter.defineRule(code, context => ({
14751454
Literal(node) {
14761455
context.report(node, context.getFilename());
@@ -1487,7 +1466,6 @@ describe("Linter", () => {
14871466
});
14881467

14891468
it("defaults filename to '<input>'", () => {
1490-
linter.reset();
14911469
linter.defineRule(code, context => ({
14921470
Literal(node) {
14931471
context.report(node, context.getFilename());
@@ -1522,8 +1500,6 @@ describe("Linter", () => {
15221500
const config = { rules: { strict: 2 } };
15231501
const codeA = "/*eslint strict: 0*/ function bar() { return 2; }";
15241502
const codeB = "function foo() { return 1; }";
1525-
1526-
linter.reset();
15271503
let messages = linter.verify(codeA, config, filename, false);
15281504

15291505
assert.equal(messages.length, 0);
@@ -1536,8 +1512,6 @@ describe("Linter", () => {
15361512
const config = { rules: { quotes: [2, "double"] } };
15371513
const codeA = "/*eslint quotes: 0*/ function bar() { return '2'; }";
15381514
const codeB = "function foo() { return '1'; }";
1539-
1540-
linter.reset();
15411515
let messages = linter.verify(codeA, config, filename, false);
15421516

15431517
assert.equal(messages.length, 0);
@@ -1550,8 +1524,6 @@ describe("Linter", () => {
15501524
const config = { rules: { quotes: [2, "double"] } };
15511525
const codeA = "/*eslint quotes: [0, \"single\"]*/ function bar() { return '2'; }";
15521526
const codeB = "function foo() { return '1'; }";
1553-
1554-
linter.reset();
15551527
let messages = linter.verify(codeA, config, filename, false);
15561528

15571529
assert.equal(messages.length, 0);
@@ -1564,8 +1536,6 @@ describe("Linter", () => {
15641536
const config = { rules: { "no-unused-vars": [2, { vars: "all" }] } };
15651537
const codeA = "/*eslint no-unused-vars: [0, {\"vars\": \"local\"}]*/ var a = 44;";
15661538
const codeB = "var b = 55;";
1567-
1568-
linter.reset();
15691539
let messages = linter.verify(codeA, config, filename, false);
15701540

15711541
assert.equal(messages.length, 0);
@@ -1691,8 +1661,6 @@ describe("Linter", () => {
16911661
const config = { rules: { "test-plugin/test-rule": 2 } };
16921662
const codeA = "/*eslint test-plugin/test-rule: 0*/ var a = \"trigger violation\";";
16931663
const codeB = "var a = \"trigger violation\";";
1694-
1695-
linter.reset();
16961664
let messages = linter.verify(codeA, config, filename, false);
16971665

16981666
assert.equal(messages.length, 0);
@@ -2907,16 +2875,6 @@ describe("Linter", () => {
29072875
});
29082876
});
29092877

2910-
describe("saveState", () => {
2911-
it("should save the state when saveState is passed as an option", () => {
2912-
2913-
const spy = sinon.spy(linter, "reset");
2914-
2915-
linter.verify("foo;", {}, { saveState: true });
2916-
assert.equal(spy.callCount, 0);
2917-
});
2918-
});
2919-
29202878
it("should report warnings in order by line and column when called", () => {
29212879

29222880
const code = "foo()\n alert('test')";

‎tests/lib/util/source-code.js

-5
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,6 @@ describe("SourceCode", () => {
216216

217217
const sandbox = sinon.sandbox.create();
218218

219-
beforeEach(() => {
220-
linter.reset();
221-
});
222-
223219
afterEach(() => {
224220
sandbox.verifyAndRestore();
225221
});
@@ -905,7 +901,6 @@ describe("SourceCode", () => {
905901

906902

907903
beforeEach(() => {
908-
linter.reset();
909904
unusedAssertionFuncs = new Set();
910905
});
911906

‎tests/tools/eslint-fuzzer.js

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ describe("eslint-fuzzer", function() {
3838
});
3939

4040
after(() => {
41-
linter.reset();
4241
configRule.createCoreRuleConfigs.restore();
4342
});
4443

0 commit comments

Comments
 (0)
Please sign in to comment.