Skip to content
Open
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
19 changes: 19 additions & 0 deletions etc/eslint/rules/stdlib.js
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@
* // Bad...
*
* /**
* * Fréchet distribution constructor.

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

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unknown word: "échet"
* *
* * @module @stdlib/stats/base/dists/frechet/ctor
* *
Expand All @@ -866,7 +866,7 @@
* // Good...
*
* /**
* * Fréchet distribution constructor.

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

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unknown word: "échet"
* *
* * @module @stdlib/stats/base/dists/frechet/ctor
* *
Expand Down Expand Up @@ -4157,6 +4157,25 @@
*/
rules[ 'stdlib/no-empty-comments' ] = 'error';

/**
* Disallow string concatenation in error messages.
*
* @name no-error-string-concat
* @memberof rules
* @type {string}
* @default 'error'
*
* @example
* // Bad...
* throw new Error( 'invalid argument. Value: `' + value + '`.' );
*
* @example
* // Good...
* throw new Error( 'unexpected error.' );
* throw new Error( format( 'invalid argument. Value: `%s`.', value ) );
*/
rules[ 'stdlib/no-error-string-concat' ] = 'error';

/**
* Enforce that `require()` expressions are not immediately invoked.
*
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 @@ -882,6 +882,15 @@ setReadOnly( rules, 'no-dynamic-require', require( '@stdlib/_tools/eslint/rules/
*/
setReadOnly( rules, 'no-empty-comments', require( '@stdlib/_tools/eslint/rules/no-empty-comments' ) );

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

/**
* @name no-immediate-require
* @memberof rules
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<!--

@license Apache-2.0

Copyright (c) 2025 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-error-string-concat

> [ESLint rule][eslint-rules] disallowing string concatenation in error messages.

<section class="intro">

</section>

<!-- /.intro -->

<section class="usage">

## Usage

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

#### rule

[ESLint rule][eslint-rules] disallowing string concatenation in error messages.

**Bad**:

<!-- run-disable -->

<!-- eslint-disable stdlib/no-error-string-concat -->

```javascript
throw new Error( 'invalid argument. Value: `' + value + '`.' );
```

**Good**:

<!-- run-disable -->

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

throw new Error( format( 'invalid argument. Value: `%s`.', value ) );
```

</section>

<!-- /.usage -->

<section class="examples">

## Examples

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

var linter = new Linter();
var result;
var code;

code = 'throw new Error( \'invalid argument. Value: `\' + value + \'`.\' );';

linter.defineRule( 'no-error-string-concat', rule );

result = linter.verify( code, {
'rules': {
'no-error-string-concat': 'error'
}
});
/* returns
[
{
'ruleId': 'no-error-string-concat',
'severity': 2,
'message': 'Use `@stdlib/string/format` instead of string concatenation in error messages.',
'line': 1,
'column': 18,
'nodeType': 'BinaryExpression',
'endLine': 1,
'endColumn': 61
}
]
*/
```

</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

</section>

<!-- /.links -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2025 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 result;
var code;

code = 'throw new Error( \'invalid argument. Value: `\' + value + \'`.\' );';

linter.defineRule( 'no-error-string-concat', rule );

result = linter.verify( code, {
'rules': {
'no-error-string-concat': 'error'
}
});
console.log( result );
/* =>
[
{
'ruleId': 'no-error-string-concat',
'severity': 2,
'message': 'Use `@stdlib/string/format` instead of string concatenation in error messages.',
'line': 1,
'column': 18,
'nodeType': 'BinaryExpression',
'endLine': 1,
'endColumn': 61
}
]
*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2025 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 string concatenation in error messages.
*
* @module @stdlib/_tools/eslint/rules/no-error-string-concat
*
* @example
* var rule = require( '@stdlib/_tools/eslint/rules/no-error-string-concat' );
*
* console.log( rule );
*/

// MODULES //

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


// EXPORTS //

module.exports = main;
Loading