Skip to content

Latest commit

 

History

History
128 lines (84 loc) · 2.77 KB

File metadata and controls

128 lines (84 loc) · 2.77 KB

no-bench-string-concat

ESLint rule enforcing that @stdlib/string/format is used instead of string concatenation in benchmark descriptions.

Usage

var rule = require( '@stdlib/_tools/eslint/rules/no-bench-string-concat' );

rule

ESLint rule enforcing that @stdlib/string/format is used instead of string concatenation in benchmark descriptions.

Bad:

bench( pkg+':len='+len, function benchmark( b ) {
    // ...
});

Good:

var format = require( '@stdlib/string/format' );

bench( format( '%s:len=%d', pkg, len ), function benchmark( b ) {
    // ...
});

Examples

var Linter = require( 'eslint' ).Linter;
var rule = require( '@stdlib/_tools/eslint/rules/no-bench-string-concat' );

var linter = new Linter();
linter.defineRule( 'no-bench-string-concat', rule );

var code = 'bench( pkg+\':len=\'+len, f );';
var result = linter.verify( code, {
    'rules': {
        'no-bench-string-concat': 'error'
    }
});
/* returns
    [
        {
            'ruleId': 'no-bench-string-concat',
            'severity': 2,
            'message': 'Use `@stdlib/string/format` instead of string concatenation for benchmark descriptions.',
            'line': 1,
            'column': 8,
            'nodeType': 'BinaryExpression',
            'endLine': 1,
            'endColumn': 23
        }
    ]
*/