Skip to content

Latest commit

 

History

History
298 lines (212 loc) · 3.39 KB

prefer-standalone-component.md

File metadata and controls

298 lines (212 loc) · 3.39 KB

@angular-eslint/prefer-standalone-component

⚠️ THIS RULE IS DEPRECATED

Please use @angular-eslint/prefer-standalone instead.


Ensures component standalone property is set to true in the component decorator

  • Type: suggestion
  • 🔧 Supports autofix (--fix)

Rule Options

The rule does not have any configuration options.


Usage Examples

The following examples are generated automatically from the actual unit tests within the plugin, so you can be assured that their behavior is accurate based on the current commit.


❌ - Toggle examples of incorrect code for this rule

Default Config

{
  "rules": {
    "@angular-eslint/prefer-standalone-component": [
      "error"
    ]
  }
}

❌ Invalid Code

@Component({})
~~~~~~~~~~~~~~
class Test {}



Default Config

{
  "rules": {
    "@angular-eslint/prefer-standalone-component": [
      "error"
    ]
  }
}

❌ Invalid Code

@Component({ standalone: false })
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class Test {}



Default Config

{
  "rules": {
    "@angular-eslint/prefer-standalone-component": [
      "error"
    ]
  }
}

❌ Invalid Code

@Component({
~~~~~~~~~~~~
standalone: false,
~~~~~~~~~~~~~~~~~~
template: '<div></div>'
~~~~~~~~~~~~~~~~~~~~~~~
})
~~
class Test {}



Default Config

{
  "rules": {
    "@angular-eslint/prefer-standalone-component": [
      "error"
    ]
  }
}

❌ Invalid Code

@Component({
~~~~~~~~~~~~
template: '<div></div>'
~~~~~~~~~~~~~~~~~~~~~~~
})
~~
class Test {}



Default Config

{
  "rules": {
    "@angular-eslint/prefer-standalone-component": [
      "error"
    ]
  }
}

❌ Invalid Code

@Component({
~~~~~~~~~~~~
selector: 'my-selector',
~~~~~~~~~~~~~~~~~~~~~~~
template: '<div></div>'
~~~~~~~~~~~~~~~~~~~~~~~
})
~~
class Test {}



✅ - Toggle examples of correct code for this rule

Default Config

{
  "rules": {
    "@angular-eslint/prefer-standalone-component": [
      "error"
    ]
  }
}

✅ Valid Code

@Component({
  standalone: true,
})
class Test {}



Default Config

{
  "rules": {
    "@angular-eslint/prefer-standalone-component": [
      "error"
    ]
  }
}

✅ Valid Code

@Component({
  standalone: true,
  selector: 'test-selector'
})
class Test {}



Default Config

{
  "rules": {
    "@angular-eslint/prefer-standalone-component": [
      "error"
    ]
  }
}

✅ Valid Code

@Component({
  selector: 'test-selector',
  standalone: true,
  template: '<div></div>',
  styleUrls: ['./test.css']
})
class Test {}