Skip to content

Commit

Permalink
Add eslint config
Browse files Browse the repository at this point in the history
  • Loading branch information
NullVoxPopuli committed Sep 25, 2024
1 parent cc085cc commit 9bca726
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 26 deletions.
93 changes: 93 additions & 0 deletions files-override/js/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import globals from 'globals';
import js from '@eslint/js';

import ember from 'eslint-plugin-ember';
import emberRecommended from 'eslint-plugin-ember/configs/recommended';
import gjsRecommended from 'eslint-plugin-ember/configs/recommended-gjs';

import prettier from 'eslint-plugin-prettier/recommended';
import qunit from 'eslint-plugin-qunit';
import n from 'eslint-plugin-n';

import emberParser from 'ember-eslint-parser';
import babelParser from '@babel/eslint-parser';

const esmParserOptions = {
ecmaFeatures: { modules: true },
ecmaVersion: 'latest',
requireConfigFile: false,
babelOptions: {
plugins: [
['@babel/plugin-proposal-decorators', { decoratorsBeforeExport: true }],
],
},
};

export default [
js.configs.recommended,
prettier,
{
ignores: ['vendor/', 'dist/', 'node_modules/', 'coverage/', '!**/.*'],
linterOptions: {
reportUnusedDisableDirectives: 'error',
},
},
{
files: ['**/*.js'],
languageOptions: {
parser: babelParser,
parserOptions: esmParserOptions,
globals: {
...globals.browser,
},
},
plugins: {
ember: ember,
},
rules: {
...emberRecommended.rules,
...gjsRecommended.rules,
},
},
{
files: ['**/*.gjs'],
languageOptions: {
parser: emberParser,
parserOptions: esmParserOptions,
globals: {
...globals.browser,
},
},
plugins: {
ember: ember,
},
rules: {
...emberRecommended.rules,
...gjsRecommended.rules,
},
},
{
plugins: {
qunit,
},
files: ['tests/**/*-test.{js,gjs}'],
},
/**
* CJS node files
*/
{
files: ['**/*.cjs', 'config/**/*.js'],
plugins: {
n,
},

languageOptions: {
globals: {
...globals.node,
},

ecmaVersion: 6,
sourceType: 'script',
},
},
];
67 changes: 41 additions & 26 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const fs = require('fs');
const { join } = require('path');
const emberCliUpdate = require('./lib/ember-cli-update');
const copyWithTemplate = require('./lib/copy-with-template');
const { rm } = require('fs/promises');
const { rm, readFile } = require('fs/promises');

const appBlueprint = Blueprint.lookup('app');

Expand Down Expand Up @@ -36,8 +36,39 @@ module.exports = {
},

async updateDeps(options) {
let manifestPath = join(options.target, 'package.json');
let manifestBuffer = await readFile(manifestPath);
let manifest = JSON.parse(manifestBuffer.toString());

let existingDeps = [
...Object.keys(manifest.dependencies || {}),
...Object.keys(manifest.devDependencies || {}),
];

let ensureLatestDeps = ['eslint', 'eslint-plugin-ember', 'eslint-plugin-n'];

// this.addPackagesToProject doesn't respect the packageManager that the blueprint specified 🙈 so we're skipping a level here
let installTask = this.taskFor('npm-install');
let uninstallTask = this.taskFor('npm-uninstall');

await uninstallTask.run({
'save-dev': true,
verbose: false,
packages: [
// Not needed anymore
'ember-fetch',
'broccoli-asset-rev',
'ember-cli-app-version',
'ember-cli-clean-css',
'ember-cli-dependency-checker',
'ember-cli-sri',
'ember-cli-terser',

...ensureLatestDeps,
].filter((depToRemove) => existingDeps.includes(depToRemove)),
packageManager: options.packageManager,
});

await installTask.run({
'save-dev': true,
verbose: false,
Expand All @@ -50,37 +81,21 @@ module.exports = {
'vite',
'@rollup/plugin-babel',
'decorator-transforms',

...ensureLatestDeps,
// Needed for eslint
'globals',
],
packageManager: options.packageManager,
});

let uninstallTask = this.taskFor('npm-uninstall');
const packages = [
'ember-fetch',
'broccoli-asset-rev',
'ember-cli-app-version',
'ember-cli-clean-css',
'ember-cli-dependency-checker',
'ember-cli-sri',
'ember-cli-terser',
];

for (const package of packages) {
try {
await uninstallTask.run({
'save-dev': true,
verbose: false,
packages: [package],
packageManager: options.packageManager,
});
} catch {
console.log(`Could not uninstall ${package}`);
}
}
},

async afterInstall(options) {
const filesToDelete = ['app/index.html'];
const filesToDelete = [
'app/index.html',
// replaced with the new ESLint flat config
'.eslintrc.js',
];

for (let file of filesToDelete) {
await rm(join(options.target, file));
Expand Down

0 comments on commit 9bca726

Please sign in to comment.