question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add support for a plugin system.

See original GitHub issue

In order to allow customization that is more organization specific (where a given rule may not be applicable to a broad audience) I would like to add support for a plugin system to ember-template-lint.

More concretely, I propose that:

  • We add a new plugins key to the .template-lintrc.js file. It would be an array that would allow entries to be either of the following:

    • An object with the following properties (both are optional):
      • rules - An object where the keys are the rule names and the values are the rules themselves. This is roughly the same format as lib/rules/index.js ( { 'rule-name': require('./some-rule-path-whatever-lol') }).
      • configurations - An object where the keys are the names and the values are the actual config to be used for each.
    • A plain string, that is resolved (relative to the config files path) and then required. When required it must have the same format as the object mentioned above.
  • We expand extends to allow both a string and an array. The array contents would only allow strings and each entry must resolve to a known config.

  • Expose public API’s for our custom testing harness (still needs more research).

  • In ember-cli-template-lint we create a blueprint for creating rules in an ember-cli project/addon (with tests).


Example config:

module.exports = {
  plugins: [
    // this would work (we would require and expect it to export a similar structure to the below object):
    'something-something-npm-package',

    // and this (for in project rules):
    {
      rules: [
        'disallow-inline-components': require('./lib/template-lint-rules/disallow-inline-components')
      ],
      configurations: [
        'no-inline': {
            rules: {
              'disallow-inline-components': true
            }
        }
      ]
    },
  ],

  extends: [
    'recommended',
    'no-inline'
  ],

  rules: {
    'bare-strings': true
  }
}

Open questions:

  • Should we add a name property to the plugin object and make it required? (might be nice for warnings and deprecations down the line)
  • Somewhat related to name, should we prefix config names with the plugin name? (i.e. "ember-template-lint-plugin-a11y:recommended"? (I’m leaning towards no, but it does make it easier to see where each config is coming from…)
  • Should we allow a plugin config to extend another config? (seems like it should be supported/allowed to me…)

Initial proposal - 2016-11-10
  • We add a new plugins key to the .template-lintrc.js file. It would be an array that would allow entries to be either of the following:

    • An object in the same format as lib/rules/index.js ( { 'rule-name': require('./some-rule-path-whatever-lol') }).
    • A plain string, that is resolved (relative to the config files path) and then required. When required it must have the same format as the object mentioned above.
  • We expand extends to allow both a string and an array. The array contents would be roughly the same allowed values as plugins (mentioned above).

  • Expose public API’s for our custom testing harness (still needs more research).

  • In ember-cli-template-lint we create a blueprint for creating rules in an ember-cli project/addon (with tests).


Example config:

module.exports = {
  plugins: [
    // this would work (we would require and expect it to export a similar structure to the below object):
    'something-something-npm-package',

    // and this (for in project rules):
    {
      'custom-rule-name-here': require('./lib/template-lint-rules/custom-rule-name-here')
    },
  ],

  extends: [
    'recommended',
    'something-something-npm-package/config'
  ],

  rules: {
    'bare-strings': true
  }
}

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
rwjbluecommented, Jan 23, 2017

The main thrust of this has landed (thanks to @ppcano!). I’m going to close this issue (since its basically done) and open more targeted issues for the remaining pieces.

0reactions
ppcanocommented, Nov 20, 2016

@rwjblue

Please, may you confirm the open questions.

I say YES to all.

Should we add a name property to the plugin object and make it required? Somewhat related to name, should we prefix config names with the plugin name?

Prefixing config name prevents config name collision of different plugins.

module.exports = {
  plugins: [
    // this would work (we would require and expect it to export a similar structure to the below object):
    'something-something-npm-package',

    // and this (for in project rules):
    {
      name: 'inline-plugin',
      rules: {
        'disallow-inline-components': require('./lib/template-lint-rules/disallow-inline-components')
      },
      configurations: {
        'no-inline': {
            rules: {
              'disallow-inline-components': true
            }
        }
      }
    },
  ],

  extends: [
    'recommended',
    'inline-plugin:no-inline'
  ],

  rules: {
    'bare-strings': true
  }
}

Read more comments on GitHub >

github_iconTop Results From Across the Web

Create a .NET Core application with plugins - Microsoft Learn
Structure a project to support plugins. Create a custom AssemblyLoadContext to load each plugin. Use the System.Runtime.Loader.
Read more >
How to Design Software — Plugin Systems | by Joseph Gefroh
Plugin systems come in many shapes and forms — to illustrate the design, the following basic concepts can help frame your thinking:.
Read more >
Build a Plugin System With Node.js - Fusebit
Plugin : Represents an independent functionality executed in the context of a system service that extends the system functionality.
Read more >
Build A Plugin System — Node.js | Medium
How to Build A Plugin System with Node.js ... Add support for node packages to be used as a plugin, in place of...
Read more >
Implementing a Plugin Architecture in a Python Application
Learn how to add a plugin framework to a Python application. ... When a program supports plug-ins, it enables customization (Wikipedia).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found