Skip to content

Commit

Permalink
add gjs/gts recommended configs
Browse files Browse the repository at this point in the history
  • Loading branch information
patricklx committed Nov 2, 2023
1 parent 19bceeb commit d74a07e
Show file tree
Hide file tree
Showing 12 changed files with 167 additions and 58 deletions.
4 changes: 3 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
coverage/
node_modules
lib/recommended-rules.js
lib/recommended-rules-gjs.js
lib/recommended-rules-gts.js

# Contains <template> in js markdown
docs/rules/no-empty-glimmer-component-classes.md
docs/rules/no-empty-glimmer-component-classes.md
46 changes: 41 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,42 @@ learn more [here](https://github.com/ember-template-imports/ember-template-impor
module.exports = {
overrides: [
{
files: ['**/*.gts', '**/*.gjs'],
files: ['**/*.{js,ts,gjs,gts}'],
plugins: ['ember'],
extends: [
'eslint:recommended',
'plugin:ember/gts-recommended', // or other configuration
],
rules: {
// override / enable optional rules
'ember/no-replace-test-comments': 'error'
}
},
{
files: ['**/*.gts'],
parser: 'eslint-plugin-ember/gjs-gts-parser',
plugins: ['ember'],
extends: [
'eslint:recommended',
'plugin:ember/gts-recommended', // or other configuration
],
},
{
files: ['**/*.gjs'],
parser: 'eslint-plugin-ember/gjs-gts-parser',
}
plugins: ['ember'],
extends: [
'eslint:recommended',
'plugin:ember/gjs-recommended', // or other configuration
],
},
{
files: ['tests/**/*.{js,ts,gjs,gts}'],
rules: {
// override / enable optional rules
'ember/no-replace-test-comments': 'error'
}
},
],
};
```
Expand All @@ -64,9 +97,12 @@ module.exports = {

<!-- begin auto-generated configs list -->

| | Name |
| :- | :------------ |
|| `recommended` |
| | Name |
| :- | :---------------- |
| | `base` |
|| `recommended` |
| | `recommended-gjs` |
| | `recommended-gts` |

<!-- end auto-generated configs list -->

Expand Down
16 changes: 16 additions & 0 deletions docs/svgs/gjs.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions docs/svgs/gts.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions lib/config/base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module.exports = {
root: true,

parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
},

env: {
browser: true,
es2020: true,
},

plugins: ['ember'],

overrides: [
/**
* We don't want to *always* have the preprocessor active,
* it's only relevant on gjs and gts files to detect if eslint config is correctly setup for this files.
*/
{
files: ['**/*.{gts,gjs}'],
parser: 'eslint-plugin-ember/gjs-gts-parser',
processor: 'ember/<noop>',
},
],
};
7 changes: 7 additions & 0 deletions lib/config/recommended-gjs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const base = require('./base');
const gjsRules = require('../recommended-rules-gjs');

module.exports = {
...base,
rules: gjsRules,
};
7 changes: 7 additions & 0 deletions lib/config/recommended-gts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const base = require('./base');
const gtsRules = require('../recommended-rules-gts');

module.exports = {
...base,
rules: gtsRules,
};
33 changes: 2 additions & 31 deletions lib/config/recommended.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,7 @@
const base = require('./base');
const rules = require('../recommended-rules');

module.exports = {
root: true,

parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
},

env: {
browser: true,
es2020: true,
},

plugins: ['ember'],

...base,
rules,

overrides: [
/**
* We don't want to *always* have the preprocessor active,
* it's only relevant on gjs and gts files.
*
* Additionally, we need to declare a global (which is private API)
* so that ESLint doesn't report errors about the variable being undefined.
* While this is true, it's a temporary thing for babel to do further processing
* on -- and isn't relevant to user-land code.
*/
{
files: ['**/*.gts', '**/*.gjs'],
parser: 'eslint-plugin-ember/gjs-gts-parser',
processor: 'ember/<noop>',
},
],
};
7 changes: 7 additions & 0 deletions lib/recommended-rules-gjs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* IMPORTANT!
* This file has been automatically generated.
* In order to update its content based on rules'
* definitions, execute "npm run update"
*/
module.exports = {}
7 changes: 7 additions & 0 deletions lib/recommended-rules-gts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* IMPORTANT!
* This file has been automatically generated.
* In order to update its content based on rules'
* definitions, execute "npm run update"
*/
module.exports = {}
45 changes: 25 additions & 20 deletions scripts/update-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,35 @@ const path = require('path');
// Main
// ------------------------------------------------------------------------------

const root = path.resolve(__dirname, '../lib/rules');
const recommendedRulesFile = path.resolve(__dirname, '../lib/recommended-rules.js');

const rules = fs
.readdirSync(root)
.filter((file) => path.extname(file) === '.js')
.map((file) => path.basename(file, '.js'))
.map((fileName) => [fileName, require(path.join(root, fileName))]); // eslint-disable-line import/no-dynamic-require

const recommendedRules = rules.reduce((obj, entry) => {
const name = `ember/${entry[0]}`;
const recommended = entry[1].meta.docs.recommended;
if (recommended) {
obj[name] = 'error'; // eslint-disable-line no-param-reassign
}
return obj;
}, {});

const recommendedRulesContent = `/*
function generate(filename, filter) {
const root = path.resolve(__dirname, '../lib/rules');
const recommendedRulesFile = path.resolve(__dirname, filename);

const rules = fs
.readdirSync(root)
.filter((file) => path.extname(file) === '.js')
.map((file) => path.basename(file, '.js'))
.map((fileName) => [fileName, require(path.join(root, fileName))]); // eslint-disable-line import/no-dynamic-require

const recommendedRules = rules.reduce((obj, entry) => {
const name = `ember/${entry[0]}`;
if (filter(entry)) {
obj[name] = 'error'; // eslint-disable-line no-param-reassign
}
return obj;
}, {});

const recommendedRulesContent = `/*
* IMPORTANT!
* This file has been automatically generated.
* In order to update its content based on rules'
* definitions, execute "npm run update"
*/
module.exports = ${JSON.stringify(recommendedRules, null, 2)}`;

fs.writeFileSync(recommendedRulesFile, recommendedRulesContent);
fs.writeFileSync(recommendedRulesFile, recommendedRulesContent);
}

generate('../lib/recommended-rules.js', (entry) => entry[1].meta.docs.recommended);
generate('../lib/recommended-rules-gjs.js', (entry) => entry[1].meta.docs.category === 'gjs');
generate('../lib/recommended-rules-gts.js', (entry) => entry[1].meta.docs.category === 'gts');
10 changes: 9 additions & 1 deletion tests/plugin-exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

const plugin = require('../lib');
const ember = require('../lib/utils/ember');
const base = require('../lib/config/base');
const recommended = require('../lib/config/recommended');
const recommendedGjs = require('../lib/config/recommended-gjs');
const recommendedGts = require('../lib/config/recommended-gts');

describe('plugin exports', () => {
describe('utils', () => {
Expand All @@ -13,7 +16,12 @@ describe('plugin exports', () => {

describe('configs', () => {
it('has the right configurations', () => {
expect(plugin.configs).toStrictEqual({ recommended });
expect(plugin.configs).toStrictEqual({
base,
recommended,
'recommended-gjs': recommendedGjs,
'recommended-gts': recommendedGts,
});
});
});
});

0 comments on commit d74a07e

Please sign in to comment.