Skip to content

Commit

Permalink
Fix links
Browse files Browse the repository at this point in the history
  • Loading branch information
nzakas committed Dec 22, 2023
1 parent 481ef88 commit f66e077
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 91 deletions.
4 changes: 2 additions & 2 deletions docs/src/_includes/components/rule-categories.macro.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<div class="rule-category">
<span class="rule-category__icon"><span class="visually-hidden">Recommended</span></span>
<p class="rule-category__description">
The <code>"extends": "eslint:recommended"</code> property in a <a href="../use/configure/configuration-files#extending-configuration-files">configuration file</a> enables this rule
Using the <code>recommended</code> config from <code>@eslint/js</code> in a <a href="../use/configure/configuration-files#using-predefined-configurations">configuration file</a> enables this rule
</p>
</div>
{%- endif -%}
Expand All @@ -32,7 +32,7 @@
<div class="rule-category">
<span class="rule-category__icon"><span class="visually-hidden">Recommended</span></span>
<p class="rule-category__description">
if the <code>"extends": "eslint:recommended"</code> property in a configuration file enables the rule.
if the <code>recommended</code> config from <code>@eslint/js</code> in a configuration file enables the rule.
</p>
</div>
{%- endmacro -%}
Expand Down
2 changes: 1 addition & 1 deletion docs/src/extend/custom-rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ The source file for a rule exports an object with the following properties. Both
* `docs`: (`object`) Required for core rules and optional for custom rules. Core rules have specific entries inside of `docs` while custom rules can include any properties that you need. The following properties are only relevant when working on core rules.

* `description`: (`string`) Provides the short description of the rule in the [rules index](../rules/).
* `recommended`: (`boolean`) Specifies whether the `"extends": "eslint:recommended"` property in a [configuration file](../use/configure/configuration-files#extending-configuration-files) enables the rule.
* `recommended`: (`boolean`) Specifies whether the rule is enabled by the `recommended` config from `@eslint/js`.
* `url`: (`string`) Specifies the URL at which the full documentation can be accessed (enabling code editors to provide a helpful link on highlighted rule violations).

* `fixable`: (`string`) Either `"code"` or `"whitespace"` if the `--fix` option on the [command line](../use/command-line-interface#--fix) automatically fixes problems reported by the rule.
Expand Down
41 changes: 1 addition & 40 deletions docs/src/rules/no-undef.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ This rule can help you locate potential ReferenceErrors resulting from misspelli

## Rule Details

Any reference to an undeclared variable causes a warning, unless the variable is explicitly mentioned in a `/*global ...*/` comment, or specified in the [`globals` key in the configuration file](../use/configure/language-options#using-configuration-files-1). A common use case for these is if you intentionally use globals that are defined elsewhere (e.g. in a script sourced from HTML).
Any reference to an undeclared variable causes a warning, unless the variable is explicitly mentioned in a `/*global ...*/` comment, or specified in the [`globals` key in the configuration file](../use/configure/language-options#specifying-globals). A common use case for these is if you intentionally use globals that are defined elsewhere (e.g. in a script sourced from HTML).

Examples of **incorrect** code for this rule:

Expand Down Expand Up @@ -95,45 +95,6 @@ if(typeof a === "string"){}

:::

## Environments

For convenience, ESLint provides shortcuts that pre-define global variables exposed by popular libraries and runtime environments. This rule supports these environments, as listed in [Specifying Environments](../use/configure/language-options#specifying-environments). A few examples are given below.

### browser

Examples of **correct** code for this rule with `browser` environment:

::: correct

```js
/*eslint no-undef: "error"*/
/*eslint-env browser*/

setTimeout(function() {
alert("Hello");
});
```

:::

### Node.js

Examples of **correct** code for this rule with `node` environment:

::: correct

```js
/*eslint no-undef: "error"*/
/*eslint-env node*/

var fs = require("fs");
module.exports = function() {
console.log(fs);
};
```

:::

## When Not To Use It

If explicit declaration of global variables is not to your taste.
Expand Down
5 changes: 2 additions & 3 deletions docs/src/rules/strict.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ In **ECMAScript** modules, which always have strict mode semantics, the directiv

This rule requires or disallows strict mode directives.

This rule disallows strict mode directives, no matter which option is specified, if ESLint configuration specifies either of the following as [parser options](../use/configure/language-options#specifying-parser-options):
This rule disallows strict mode directives, no matter which option is specified, if ESLint configuration specifies either of the following as [parser options](../use/configure/language-options#specifying-javascript-options):

* `"sourceType": "module"` that is, files are **ECMAScript** modules
* `"impliedStrict": true` property in the `ecmaFeatures` object
Expand All @@ -73,8 +73,7 @@ This rule has a string option:

The `"safe"` option corresponds to the `"global"` option if ESLint considers a file to be a **Node.js** or **CommonJS** module because the configuration specifies either of the following:

* `node` or `commonjs` [environments](../use/configure/language-options#specifying-environments)
* `"globalReturn": true` property in the `ecmaFeatures` object of [parser options](../use/configure/language-options#specifying-parser-options)
* `"globalReturn": true` property in the `ecmaFeatures` object of [parser options](../use/configure/language-options#specifying-default-parser-options)

Otherwise the `"safe"` option corresponds to the `"function"` option. Note that if `"globalReturn": false` is explicitly specified in the configuration, the `"safe"` option will correspond to the `"function"` option regardless of the specified environment.

Expand Down
4 changes: 2 additions & 2 deletions docs/src/use/configure/configuration-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -317,13 +317,13 @@ export default [
js.configs.recommended,
{
rules: {
semi: ["warn", "always"]
"no-unused-vars": "warn"
}
}
];
```

Here, the `js.configs.recommended` predefined configuration is applied first and then another configuration object adds the desired configuration for `semi`.
Here, the `js.configs.recommended` predefined configuration is applied first and then another configuration object adds the desired configuration for `no-unused-vars`.

You can apply these predefined configs to just a subset of files by specifying a config object with a `files` key, like this:

Expand Down
11 changes: 4 additions & 7 deletions docs/src/use/configure/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ All of these options give you fine-grained control over how ESLint treats your c
[**Configuration Files**](configuration-files)

* [Configuration File Format](./configuration-files#configuration-file)
* [Using Configuration Files](./configuration-files#using-configuration-files)
* [Configuration Objects](./configuration-files#configuration-objects)
* [Configuring Shared Settings](./configuration-files#configuring-shared-settings)
* [Cascading and Hierarchy](./configuration-files#cascading-and-hierarchy)
* [Extending Configuration Files](./configuration-files#extending-configuration-files)
* [Configuration File Resolution](./configuration-files#configuration-file-resolution)
* [Configuration Based on Glob Patterns](./configuration-files#configuration-based-on-glob-patterns)

[**Configure Language Options**](language-options)
Expand All @@ -53,8 +52,6 @@ All of these options give you fine-grained control over how ESLint treats your c

[**Ignore Files**](ignore)

* [`ignorePatterns` in Config Files](./ignore#ignorepatterns-in-config-files)
* [The `.eslintignore` File](./ignore#the-eslintignore-file)
* [Using an Alternate File](./ignore#using-an-alternate-file)
* [Using eslintIgnore in package.json](./ignore#using-eslintignore-in-packagejson)
* [Ignoring Files](./ignore#ignoring-files)
* [Unignoring Files](./ignore#ignoring-files)
* [Ignored File Warnings](./ignore#ignored-file-warnings)
4 changes: 2 additions & 2 deletions docs/src/use/configure/migration-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ To learn more about the flat config format, refer to [this blog post](https://es

For reference information on these configuration formats, refer to the following documentation:

* [eslintrc configuration files](configuration-files)
* [flat configuration files](configuration-files-new)
* [eslintrc configuration files](configuration-files-deprecated)
* [flat configuration files](configuration-files)

## Start Using Flat Config Files

Expand Down
2 changes: 1 addition & 1 deletion docs/src/use/configure/parser.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ eleventyNavigation:
---

::: tip
This page explains how to configure parsers using the flat config format. For the deprecated eslintrc format, [see the deprecated documentation](parsers-deprecated).
This page explains how to configure parsers using the flat config format. For the deprecated eslintrc format, [see the deprecated documentation](parser-deprecated).
:::

You can use custom parsers to convert JavaScript code into an abstract syntax tree for ESLint to evaluate. You might want to add a custom parser if your code isn't compatible with ESLint's default parser, Espree.
Expand Down
2 changes: 1 addition & 1 deletion docs/src/use/core-concepts.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ For more information, refer to [Rules](../rules/).

Rules may optionally provide fixes for violations that they find. Fixes safely correct the violation without changing application logic.

Fixes may be applied automatically with the [`--fix` command line option](https://eslint.org/docs/latest/use/command-line-interface#--fix) and via editor extensions.
Fixes may be applied automatically with the [`--fix` command line option](command-line-interface#--fix) and via editor extensions.

Rules that may provide fixes are marked with 🔧 in [Rules](../rules/).

Expand Down
73 changes: 41 additions & 32 deletions docs/src/use/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,34 +64,45 @@ yarn run eslint yourfile.js

**Note:** If you are coming from a version before 1.0.0 please see the [migration guide](migrating-to-1.0.0).

After running `npm init @eslint/config`, you'll have an `.eslintrc.{js,yml,json}` file in your directory. In it, you'll see some rules configured like this:

```json
{
"rules": {
"semi": ["error", "always"],
"quotes": ["error", "double"]
After running `npm init @eslint/config`, you'll have an `eslint.config.js` file in your directory. In it, you'll see some rules configured like this:

```js
// eslint.config.js
export default [
{
rules: {
"no-unused-vars": "error",
"no-undef": "error"
}
}
}
];
```

The names `"semi"` and `"quotes"` are the names of [rules](../rules) in ESLint. The first value is the error level of the rule and can be one of these values:
The names `"no-unused-vars"` and `"no-undef"` are the names of [rules](../rules) in ESLint. The first value is the error level of the rule and can be one of these values:

* `"off"` or `0` - turn the rule off
* `"warn"` or `1` - turn the rule on as a warning (doesn't affect exit code)
* `"error"` or `2` - turn the rule on as an error (exit code will be 1)

The three error levels allow you fine-grained control over how ESLint applies rules (for more configuration options and details, see the [configuration docs](configure/)).

Your `.eslintrc.{js,yml,json}` configuration file will also include the line:
Your `eslint.config.js` configuration file will also include a recommended configuration, like this:

```js
// eslint.config.js
import js from "@eslint/js";

export default [
js.configs.recommended,

```json
{
"extends": "eslint:recommended"
}
rules: {
"no-unused-vars": "warn",
"no-undef": "warn"
}
];
```

Because of this line, all of the rules marked "(recommended)" on the [rules page](../rules) will be turned on. Alternatively, you can use configurations that others have created by searching for "eslint-config" on [npmjs.com](https://www.npmjs.com/search?q=eslint-config). ESLint will not lint your code unless you extend from a shared configuration or explicitly turn rules on in your configuration.
The `js.configs.recommended` object contains configuration to ensure that all of the rules marked as recommended on the [rules page](../rules) will be turned on. Alternatively, you can use configurations that others have created by searching for "eslint-config" on [npmjs.com](https://www.npmjs.com/search?q=eslint-config). ESLint will not lint your code unless you extend from a shared configuration or explicitly turn rules on in your configuration.

## Global Install

Expand All @@ -103,34 +114,32 @@ You can also manually set up ESLint in your project.

Before you begin, you must already have a `package.json` file. If you don't, make sure to run `npm init` or `yarn init` to create the file beforehand.

1. Install the ESLint package in your project:
1. Install the ESLint packages in your project:

```shell
npm install --save-dev eslint
npm install --save-dev eslint @eslint/js
```

1. Add an `.eslintrc` file in one of the [supported configuration file formats](./configure/configuration-files#configuration-file-formats).
1. Add an `eslint.config.js` file:

```shell
# Create JavaScript configuration file
touch .eslintrc.js
touch eslint.config.js
```

1. Add configuration to the `.eslintrc` file. Refer to the [Configure ESLint documentation](configure/) to learn how to add rules, environments, custom configurations, plugins, and more.
1. Add configuration to the `eslint.config.js` file. Refer to the [Configure ESLint documentation](configure/) to learn how to add rules, custom configurations, plugins, and more.

```js
// .eslintrc.js example
module.exports = {
"env": {
"browser": true,
"es2021": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
}
import js from "@eslint/js";

export default [
js.configs.recommended,

rules: {
"no-unused-vars": "warn",
"no-undef": "warn"
}
];
```

1. Lint code using the ESLint CLI:
Expand Down

0 comments on commit f66e077

Please sign in to comment.