Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion etc/eslint/rules/stdlib.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable stdlib/jsdoc-doctest-marker, stdlib/jsdoc-doctest, stdlib/jsdoc-example-require-spacing, stdlib/jsdoc-no-tabs */
/* eslint-disable stdlib/jsdoc-doctest-marker, stdlib/jsdoc-example-require-spacing, stdlib/jsdoc-no-tabs */

/**
* @license Apache-2.0
Expand Down Expand Up @@ -901,7 +901,7 @@
* *
* * @example
* * var Frechet = require( '@stdlib/stats/base/dists/frechet/ctor' );
* *

Check warning on line 904 in etc/eslint/rules/stdlib.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unknown word: "茅chet"
* * var frechet = new Frechet( 1.0, 1.0, 0.5 );
* *
* * var y = frechet.cdf( 0.8 );
Expand All @@ -917,7 +917,7 @@
* @memberof rules
* @type {Array}
* @default [ 'error', '`' ]
* @see [fenced-code-marker]{@link https://github.com/wooorm/remark-lint/tree/master/packages/remark-lint-fenced-code-marker}

Check warning on line 920 in etc/eslint/rules/stdlib.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unknown word: "茅chet"
*
* @example
* // Bad...
Expand Down Expand Up @@ -4442,6 +4442,26 @@
*/
rules[ 'stdlib/no-unnecessary-nested-functions' ] = 'error';

/**
* Disallow format calls that do not perform string interpolation.
*
* @name no-unnecessary-format
* @memberof rules
* @type {string}
* @default 'error'
*
* @example
* // Bad...
* var format = require( '@stdlib/string/format' );
*
* throw new Error( format( 'invalid argument.' ) );
*
* @example
* // Good...
* throw new Error( 'invalid argument.' );
*/
rules[ 'stdlib/no-unnecessary-format' ] = 'error';

/**
* Disallow the use of the `new Array()` constructor.
*
Expand Down
9 changes: 9 additions & 0 deletions lib/node_modules/@stdlib/_tools/eslint/rules/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,15 @@ setReadOnly( rules, 'no-single-property-require', require( '@stdlib/_tools/eslin
*/
setReadOnly( rules, 'no-unassigned-require', require( '@stdlib/_tools/eslint/rules/no-unassigned-require' ) );

/**
* @name no-unnecessary-format
* @memberof rules
* @readonly
* @type {Function}
* @see {@link module:@stdlib/_tools/eslint/rules/no-unnecessary-format}
*/
setReadOnly( rules, 'no-unnecessary-format', require( '@stdlib/_tools/eslint/rules/no-unnecessary-format' ) );

/**
* @name no-unnecessary-nested-functions
* @memberof rules
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
<!--

@license Apache-2.0

Copyright (c) 2026 The Stdlib Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

-->

# no-unnecessary-format

> [ESLint rule][eslint-rules] disallowing format calls that do not perform string interpolation.

<section class="intro">

</section>

<!-- /.intro -->

<section class="usage">

## Usage

```javascript
var rule = require( '@stdlib/_tools/eslint/rules/no-unnecessary-format' );
```

#### rule

[ESLint rule][eslint-rules] disallowing calls to the format function exported by [`@stdlib/string/format`][@stdlib/string/format] when the format string does not contain any placeholders. Such calls are unnecessary, as the format function simply returns the input string unchanged.

**Bad**:

<!-- run-disable -->

<!-- eslint-disable stdlib/no-unnecessary-format -->

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

throw new Error( format( 'invalid argument.' ) );
```

**Good**:

<!-- run-disable -->

```javascript
throw new Error( 'invalid argument.' );
```

</section>

<!-- /.usage -->

<section class="notes">

</section>

<!-- /.notes -->

<section class="examples">

## Examples

<!-- eslint no-undef: "error" -->

```javascript
var Linter = require( 'eslint' ).Linter;
var rule = require( '@stdlib/_tools/eslint/rules/no-unnecessary-format' );

var linter = new Linter();

var code = [
'var format = require( \'@stdlib/string/format\' );',
'',
'throw new Error( format( \'invalid argument.\' ) );'
].join( '\n' );

linter.defineRule( 'no-unnecessary-format', rule );

var result = linter.verify( code, {
'rules': {
'no-unnecessary-format': 'error'
}
});
/* returns
[
{
'ruleId': 'no-unnecessary-format',
'severity': 2,
'message': 'Unnecessary format call. No placeholders found in format string.',
'line': 3,
'column': 18,
'nodeType': 'CallExpression',
'endLine': 3,
'endColumn': 47
}
]
*/
```

</section>

<!-- /.examples -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">

</section>

<!-- /.related -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">

[eslint-rules]: https://eslint.org/docs/developer-guide/working-with-rules

[@stdlib/string/format]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/format

</section>

<!-- /.links -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

var Linter = require( 'eslint' ).Linter;
var rule = require( './../lib' );

var linter = new Linter();
var code = [
'var format = require( \'@stdlib/string/format\' );',
'',
'throw new Error( format( \'invalid argument.\' ) );'
].join( '\n' );

linter.defineRule( 'no-unnecessary-format', rule );

var results = linter.verify( code, {
'rules': {
'no-unnecessary-format': 'error'
}
});
console.log( results );
/* =>
[
{
'ruleId': 'no-unnecessary-format',
'severity': 2,
'message': 'Unnecessary format call. No placeholders found in format string.',
'line': 3,
'column': 18,
'nodeType': 'CallExpression',
'endLine': 3,
'endColumn': 47
}
]
*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2026 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

/**
* ESLint rule disallowing format calls that do not perform string interpolation.
*
* @module @stdlib/_tools/eslint/rules/no-unnecessary-format
*
* @example
* var rule = require( '@stdlib/_tools/eslint/rules/no-unnecessary-format' );
*
* console.log( rule );
*/

// MODULES //

var main = require( './main.js' );


// EXPORTS //

module.exports = main;
Loading