# no-hardcoded-ip

Rule `sonarjs/no-hardcoded-ip`. IP addresses should not be hardcoded

- Source: sonarjs
- Technologies: JavaScript
- Kind: style
- Needs type information: no
- Autofix: no
- Reach: 6.2M weekly downloads of presets that enable it
- Trend: +62.1% last quarter
- Rank: #1276 by reach, #577 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `sonarjs/no-hardcoded-ip` | yes | no | package `eslint-plugin-sonarjs` | [docs](https://rules.sonarsource.com/javascript/RSPEC-1313/) |

## Code examples

### Correct: the rule accepts this

```js
ip = process.env.IP_ADDRESS; // Compliant

const net = require('net');
var client = new net.Socket();
client.connect(80, ip, function() {
  // ...
});
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
export default [
  {
    rules: {
      "sonarjs/no-hardcoded-ip": "error",
    },
  },
];
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [SonarJS recommended](https://lintradar.dev/presets/sonarjs-recommended.md) | ESLint | `eslint-plugin-sonarjs` | 230 | 6.2M | +62.1% |

## Related rules

- [sonarjs/no-gratuitous-expressions](https://lintradar.dev/rules/sonarjs/no-gratuitous-expressions.md): Boolean expressions should not be gratuitous
- [sonarjs/no-hardcoded-passwords](https://lintradar.dev/rules/sonarjs/no-hardcoded-passwords.md): Credentials should not be hard-coded
- [sonarjs/no-globals-shadowing](https://lintradar.dev/rules/sonarjs/no-globals-shadowing.md): Special identifiers should not be bound or assigned
- [sonarjs/no-hardcoded-secrets](https://lintradar.dev/rules/sonarjs/no-hardcoded-secrets.md): Secrets should not be hard-coded
- [sonarjs/no-global-this](https://lintradar.dev/rules/sonarjs/no-global-this.md): The global "this" object should not be used
- [sonarjs/no-hook-setter-in-body](https://lintradar.dev/rules/sonarjs/no-hook-setter-in-body.md): React's useState hook should not be used directly in the render function or body of a component

---

Web page: https://lintradar.dev/rules/sonarjs/no-hardcoded-ip. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
