<commit_before>/**
 * @fileoverview Prevent redundant assignment.
 * @author <NAME>
 * @copyright 2016 <NAME>. All rights reserved.
 * See LICENSE file in root directory for full license.
 */
'use strict';

var rule = require('../rules/no-redundant-assign');
var RuleTester = require("eslint").RuleTester;

var errorMessage = 'Redundant assignment.';

var ruleTester = new RuleTester();
ruleTester.run('no-redundant-assign', rule, {
	valid: [
		// constant
		'return 5;',
		// variable
		'return foo;',
		// function invocation
		'return foo.bar();',
		// property of preceding variable
		'var foo; return foo.bar;',
		// function invocation of preceding variable
		'var foo; return foo();',
		// function invocation on preceding variable
		'var foo; return foo.bar()',
		// expression involving preceding variable
		'var foo; return foo + bar;',
		// function invocation with preceding variable as argument
		'var foo; return bar(foo);',
		// assignment of out-of-scope var
		'var foo; function() { foo = bar; return foo; };',
		// assignment of out-of-scope var, arrow function
		{ code: 'var foo; () => { foo = bar; return foo; };', ecmaFeatures: { arrowFunctions: true } },
		// assignment of out-of-scope let
		{ code: 'let foo; function() { foo = bar; return foo; };', ecmaFeatures: { blockBindings: true } },
		// assignment of out-of-scope let, arrow function
		{ code: 'let foo; () => { foo = bar; return foo; };', ecmaFeatures: { arrowFunctions: true, blockBindings: true } },
		// not the last var before return
		'var foo, bar; return foo;',
		// not the last let before return
		{ code: 'let foo, bar; return foo;', ecmaFeatures: { blockBindings: true } },
		// not the last const before return
		{ code: 'const foo = 1, bar = 2; return foo;', ecmaFeatures: { blockBindings: true } },
		// multiple var declarations
		'var foo; var bar; return foo;',
		// mixed var declarations
		{ code: 'const foo = 1; let bar; return foo;', ecmaFeatures: { blockBindings: true } }
	],
	invalid: [
		// redundant var
		{
			code: 'var foo; return foo;',
			errors: [{
				message: errorMessage,
				type: 'Identifier',
				line: 1,
				column: 5
			}]
		},
		// redundant var, within block
		{
			code: 'function() { if (bar) { var foo; return foo; } }',
			errors: [{
				message: errorMessage,
				type: 'Identifier',
				line: 1,
				column: 29
			}]
		},
		// redundant let
		{
			code: 'let foo; return foo;',
			ecmaFeatures: { blockBindings: true },
			errors: [{
				message: errorMessage,
				type: 'Identifier',
				line: 1,
				column: 5
			}]
		},
		// redundant let, within block
		{
			code: 'function() { if (bar) { let foo; return foo; } }',
			ecmaFeatures: { blockBindings: true },
			errors: [{
				message: errorMessage,
				type: 'Identifier',
				line: 1,
				column: 29
			}]
		},
		// redundant const
		{
			code: 'const foo = bar; return foo;',
			ecmaFeatures: { blockBindings: true },
			errors: [{
				message: errorMessage,
				type: 'Identifier',
				line: 1,
				column: 7
			}]
		},
		// redundant const, within block
		{
			code: 'function() { if (bar) { const foo = bar; return foo; } }',
			ecmaFeatures: { blockBindings: true },
			errors: [{
				message: errorMessage,
				type: 'Identifier',
				line: 1,
				column: 31
			}]
		},
		// reassign to var in scope
		{
			code: 'var foo; bar(); foo = baz; return foo;',
			errors: [{
				message: errorMessage,
				type: 'Identifier',
				line: 1,
				column: 17
			}]
		},
		// reassign to var in scope, within block
		{
			code: 'var foo; bar(); if (1) { foo = baz; return foo; }',
			errors: [{
				message: errorMessage,
				type: 'Identifier',
				line: 1,
				column: 26
			}]
		},
		// reassign to let in scope
		{
			code: 'let foo; bar(); foo = baz; return foo;',
			ecmaFeatures: { blockBindings: true },
			errors: [{
				message: errorMessage,
				type: 'Identifier',
				line: 1,
				column: 17
			}]
		},
		// reassign to let in scope, within block
		{
			code: 'let foo; bar(); if (1) { foo = baz; return foo; }',
			ecmaFeatures: { blockBindings: true },
			errors: [{
				message: errorMessage,
				type: 'Identifier',
				line: 1,
				column: 26
			}]
		}
	]
});<commit_msg>fix node types, add some more tests<commit_after>/**
 * @fileoverview Prevent redundant assignment.
 * @author <NAME>
 * @copyright 2016 <NAME>. All rights reserved.
 * See LICENSE file in root directory for full license.
 */
'use strict';

var rule = require('../rules/no-redundant-assign');
var RuleTester = require("eslint").RuleTester;

var varMessage = 'Redundant variable.';
var assignMessage = 'Redundant assignment.';

var ruleTester = new RuleTester();
ruleTester.run('no-redundant-assign', rule, {
	valid: [
		// constant
		'(function() { return 5; });',
		// variable
		'(function() { return foo; });',
		// function invocation
		'(function() { return foo.bar(); });',
		// property of preceding variable
		'(function() { var foo; return foo.bar; });',
		// function invocation of preceding variable
		'(function() { var foo; return foo(); });',
		// function invocation on preceding variable
		'(function() { var foo; return foo.bar() });',
		// expression involving preceding variable
		'(function() { var foo; return foo + bar; });',
		// function invocation with preceding variable as argument
		'(function() { var foo; return bar(foo); });',
		// assignment of out-of-scope var
		'(function() { var foo; (function() { foo = bar; return foo; }); });',
		// assignment of out-of-scope var, arrow function
		{ code: '(function() { var foo; (() => { foo = bar; return foo; }); });', ecmaFeatures: { arrowFunctions: true } },
		// assignment of out-of-scope let
		{ code: '(function() { let foo; (function() { foo = bar; return foo; }); });', ecmaFeatures: { blockBindings: true } },
		// assignment of out-of-scope let, arrow function
		{ code: '(function() { let foo; (() => { foo = bar; return foo; }); });', ecmaFeatures: { arrowFunctions: true, blockBindings: true } },
		// not the last var before return
		'(function() { var foo, bar; return foo; });',
		// not the last let before return
		{ code: '(function() { let foo, bar; return foo; });', ecmaFeatures: { blockBindings: true } },
		// not the last const before return
		{ code: '(function() { const foo = 1, bar = 2; return foo; });', ecmaFeatures: { blockBindings: true } },
		// multiple var declarations
		'(function() { var foo; var bar; return foo; });',
		// mixed var declarations
		{ code: '(function() { const foo = 1; let bar; return foo; });', ecmaFeatures: { blockBindings: true } }
	],
	invalid: [
		// redundant var
		{
			code: '(function() { var foo; return foo; });',
			errors: [{
				message: varMessage,
				type: 'VariableDeclarator',
				line: 1,
				column: 19
			}]
		},
		// redundant var, last in list
		{
			code: '(function() { var bar, foo; return foo; });',
			errors: [{
				message: varMessage,
				type: 'VariableDeclarator',
				line: 1,
				column: 24
			}]
		},
		// redundant initialized var, last in list
		{
			code: '(function() { var bar, foo = baz; return foo; });',
			errors: [{
				message: varMessage,
				type: 'VariableDeclarator',
				line: 1,
				column: 24
			}]
		},
		// redundant var, within block
		{
			code: '(function() { if (bar) { var foo; return foo; } });',
			errors: [{
				message: varMessage,
				type: 'VariableDeclarator',
				line: 1,
				column: 30
			}]
		},
		// redundant let
		{
			code: '(function() { let foo; return foo; });',
			ecmaFeatures: { blockBindings: true },
			errors: [{
				message: varMessage,
				type: 'VariableDeclarator',
				line: 1,
				column: 19
			}]
		},
		// redundant let, within block
		{
			code: '(function() { if (bar) { let foo; return foo; } });',
			ecmaFeatures: { blockBindings: true },
			errors: [{
				message: varMessage,
				type: 'VariableDeclarator',
				line: 1,
				column: 30
			}]
		},
		// redundant const
		{
			code: '(function() { const foo = bar; return foo; });',
			ecmaFeatures: { blockBindings: true },
			errors: [{
				message: varMessage,
				type: 'VariableDeclarator',
				line: 1,
				column: 21
			}]
		},
		// redundant const, within block
		{
			code: '(function() { if (bar) { const foo = bar; return foo; } });',
			ecmaFeatures: { blockBindings: true },
			errors: [{
				message: varMessage,
				type: 'VariableDeclarator',
				line: 1,
				column: 32
			}]
		},
		// reassign to var in scope
		{
			code: '(function() { var foo; bar(); foo = baz; return foo; });',
			errors: [{
				message: assignMessage,
				type: 'Identifier',
				line: 1,
				column: 31
			}]
		},
		// reassign to var in scope, within block
		{
			code: '(function() { var foo; bar(); if (baz) { foo = baz; return foo; } });',
			errors: [{
				message: assignMessage,
				type: 'Identifier',
				line: 1,
				column: 42
			}]
		},
		// reassign to let in scope
		{
			code: '(function() { let foo; bar(); foo = baz; return foo; });',
			ecmaFeatures: { blockBindings: true },
			errors: [{
				message: assignMessage,
				type: 'Identifier',
				line: 1,
				column: 31
			}]
		},
		// reassign to let in scope, within block
		{
			code: '(function() { let foo; bar(); if (baz) { foo = baz; return foo; } });',
			ecmaFeatures: { blockBindings: true },
			errors: [{
				message: assignMessage,
				type: 'Identifier',
				line: 1,
				column: 42
			}]
		}
	]
});
{'fraction_non_alphanumeric': 0.16436301296474873, 'fraction_numerical': 0.008678881388621022, 'mean_word_length': 2.8730290456431535, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6788114', 'n_tokens_mistral': 3683, 'n_tokens_neox': 2997, 'n_words': 980}