Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add gts/gjs configs #1944

Merged
merged 1 commit into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you add a description property to each config, it will show up in this table. Up to you if you think it would be helpful.

| :- | :---------------- |
| | `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 = {
Copy link
Member

@bmish bmish Oct 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI we had a base config before. I removed it when it didn't seem necessary #1518. It's fine if you want to add it back. We had some other interest in adding back the base config here too: #1895

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, i think it makes sense if want to go this way and provide recommended configs per file type.
btw, eslint-typescipt also has a base config (but I didnt see it documented) https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/configs/base.ts

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, seems fine to add base.

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,
});
});
});
});