Skip to content

Commit

Permalink
First cut
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronMoat committed Aug 4, 2024
1 parent 8532fd5 commit 3c5f20c
Show file tree
Hide file tree
Showing 8 changed files with 493 additions and 470 deletions.
24 changes: 16 additions & 8 deletions .changeset/changelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ const {
*/
const defaultChangelogFunctions = {
getDependencyReleaseLine: async (changesets, dependenciesUpdated) => {
if (dependenciesUpdated.length === 0) return '';
if (dependenciesUpdated.length === 0) {
return '';
}

const changesetLinks = changesets.map(
(changeset) => `- Updated dependencies [${changeset.commit}]`,
Expand Down Expand Up @@ -55,13 +57,15 @@ const gitHubChangelogFunctions = {
'Please provide a repo to this changelog generator like this:\n"changelog": ["./changelog.js", { "repo": "org/repo" }]',
);
}
if (dependenciesUpdated.length === 0) return '';
if (dependenciesUpdated.length === 0) {
return '';
}

const changesetLink = `- Updated dependencies [${(
await Promise.all(
changesets.map(async (cs) => {
if (cs.commit) {
let { links } = await getInfo({
const { links } = await getInfo({
repo: options.repo,
commit: cs.commit,
});
Expand Down Expand Up @@ -93,16 +97,17 @@ const gitHubChangelogFunctions = {

const replacedChangelog = changeset.summary
.replace(/^\s*(?:pr|pull|pull\s+request):\s*#?(\d+)/im, (_, pr) => {
let num = Number(pr);
if (!isNaN(num)) prFromSummary = num;
const num = Number(pr);
if (!isNaN(num)) {
prFromSummary = num;
}
return '';
})
.replace(/^\s*commit:\s*([^\s]+)/im, (_, commit) => {
commitFromSummary = commit;
return '';
})
.replace(/^\s*(?:author|user):\s*@?([^\s]+)/gim, (_, user) => {
usersFromSummary.push(user);
.replace(/^\s*(?:author|user):\s*@?([^\s]+)/gim, () => {
return '';
})
.trim();
Expand All @@ -113,6 +118,7 @@ const gitHubChangelogFunctions = {

const links = await (async () => {
if (prFromSummary !== undefined) {
// eslint-disable-next-line no-shadow
let { links } = await getInfoFromPullRequest({
repo: options.repo,
pull: prFromSummary,
Expand All @@ -127,7 +133,8 @@ const gitHubChangelogFunctions = {
}
const commitToFetchFrom = commitFromSummary || changeset.commit;
if (commitToFetchFrom) {
let { links } = await getInfo({
// eslint-disable-next-line no-shadow
const { links } = await getInfo({
repo: options.repo,
commit: commitToFetchFrom,
});
Expand All @@ -152,6 +159,7 @@ const gitHubChangelogFunctions = {
if (process.env.GITHUB_TOKEN) {
module.exports = gitHubChangelogFunctions;
} else {
// eslint-disable-next-line no-console
console.warn(
`Defaulting to Git-based versioning.
Enable GitHub-based versioning by setting the GITHUB_TOKEN environment variable.
Expand Down
12 changes: 12 additions & 0 deletions .changeset/small-jeans-wave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
'eslint-config-seek': major
---

Migrate to ESLint 9, `@typescript-eslint` 8.

These changes may affect your project if customising your ESLint configuration. See the individual migration guides:

- https://eslint.org/docs/latest/use/migrate-to-9.0.0
- https://typescript-eslint.io/blog/announcing-typescript-eslint-v8

As part of this migration, this project has migrated to Flat ESLint configuration. Read the migration: https://eslint.org/docs/latest/use/configure/migration-guide
262 changes: 150 additions & 112 deletions base.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
const root = require('find-root')(process.cwd());
const importX = require('eslint-plugin-import-x');
const globals = require('globals');
const babelParser = require('@babel/eslint-parser');
const tsParser = require('@typescript-eslint/parser');
const jest = require('eslint-plugin-jest');
const cypress = require('eslint-plugin-cypress');
const js = require('@eslint/js');

const { FlatCompat } = require('@eslint/eslintrc');

const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all,
});

const OFF = 0;
const ERROR = 2;
Expand Down Expand Up @@ -88,132 +103,155 @@ const settings = {
},
};

/** @type {import('eslint').Linter.Config} */
const baseConfig = {
parser: '@babel/eslint-parser',
parserOptions: {
requireConfigFile: false,
sourceType: 'module',
},
root: true,
env: {
node: true,
},
plugins: ['import-x'],
extends: ['prettier', 'plugin:import-x/typescript'],
settings,
rules: {
...baseRules,
module.exports = [
...compat.extends('prettier', 'plugin:import-x/typescript'),
{
plugins: {
'import-x': importX,
},

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

parser: babelParser,
ecmaVersion: 6,
sourceType: 'module',

parserOptions: {
requireConfigFile: false,
},
},
settings,
rules: baseRules,
},
overrides: [
{
// TypeScript config
...compat
.extends(
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/stylistic',
'prettier',
)
.map((config) => ({
...config,
files: [`**/*.{${tsExtensions}}`],
parser: '@typescript-eslint/parser',
})),
{
files: [`**/*.{${tsExtensions}}`],

languageOptions: {
parser: tsParser,
ecmaVersion: 2022,
sourceType: 'module',

parserOptions: {
// https://github.com/typescript-eslint/typescript-eslint/issues/6544
allowAutomaticSingleRunInference: true,
ecmaVersion: 2022,
project: true,
sourceType: 'module',
warnOnUnsupportedTypeScriptVersion: false,
},
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/stylistic',
'prettier',
},
settings,
rules: {
'@typescript-eslint/array-type': [ERROR, { default: 'array-simple' }],
'@typescript-eslint/consistent-type-definitions': OFF,
'@typescript-eslint/no-unused-expressions': ERROR,
'@typescript-eslint/no-unused-vars': [
ERROR,
{ argsIgnorePattern: '^_', ignoreRestSiblings: true },
],
settings,
rules: {
'@typescript-eslint/array-type': [ERROR, { default: 'array-simple' }],
'@typescript-eslint/consistent-type-definitions': OFF,
'@typescript-eslint/no-unused-expressions': ERROR,
'@typescript-eslint/no-unused-vars': [
ERROR,
{ argsIgnorePattern: '^_', ignoreRestSiblings: true },
],
'@typescript-eslint/no-use-before-define': OFF,
'@typescript-eslint/no-non-null-assertion': OFF,
'@typescript-eslint/ban-ts-comment': OFF,
'@typescript-eslint/no-explicit-any': OFF,
'@typescript-eslint/explicit-function-return-type': OFF,
'@typescript-eslint/no-empty-function': OFF,
'@typescript-eslint/no-empty-interface': OFF,
'@typescript-eslint/no-inferrable-types': [
ERROR,
{ ignoreParameters: true },
],
// prefer TypeScript exhaustiveness checking
// https://www.typescriptlang.org/docs/handbook/advanced-types.html#exhaustiveness-checking
'default-case': OFF,
'arrow-body-style': [ERROR, 'as-needed'],
// Use `typescript-eslint`'s no-shadow to avoid false positives with enums
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-shadow.md
'no-shadow': OFF,
'@typescript-eslint/no-shadow': ERROR,
'@typescript-eslint/no-use-before-define': OFF,
'@typescript-eslint/no-non-null-assertion': OFF,
'@typescript-eslint/ban-ts-comment': OFF,
'@typescript-eslint/no-explicit-any': OFF,
'@typescript-eslint/explicit-function-return-type': OFF,
'@typescript-eslint/no-empty-function': OFF,
'@typescript-eslint/no-empty-interface': OFF,
'@typescript-eslint/no-inferrable-types': [
ERROR,
{ ignoreParameters: true },
],
// prefer TypeScript exhaustiveness checking
// https://www.typescriptlang.org/docs/handbook/advanced-types.html#exhaustiveness-checking
'default-case': OFF,
'arrow-body-style': [ERROR, 'as-needed'],
// Use `typescript-eslint`'s no-shadow to avoid false positives with enums
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-shadow.md
'no-shadow': OFF,
'@typescript-eslint/no-shadow': ERROR,

// These two rules deal with autofixing type imports/exports
// https://typescript-eslint.io/rules/consistent-type-imports
'@typescript-eslint/consistent-type-imports': [
ERROR,
{ fixStyle: 'inline-type-imports' },
],
// https://typescript-eslint.io/rules/consistent-type-exports
'@typescript-eslint/consistent-type-exports': [
ERROR,
{ fixMixedExportsWithInlineTypeSpecifier: true },
],
// https://typescript-eslint.io/rules/no-import-type-side-effects
'@typescript-eslint/no-import-type-side-effects': ERROR,
// These two rules deal with autofixing type imports/exports
// https://typescript-eslint.io/rules/consistent-type-imports
'@typescript-eslint/consistent-type-imports': [
ERROR,
{ fixStyle: 'inline-type-imports' },
],
// https://typescript-eslint.io/rules/consistent-type-exports
'@typescript-eslint/consistent-type-exports': [
ERROR,
{ fixMixedExportsWithInlineTypeSpecifier: true },
],
// https://typescript-eslint.io/rules/no-import-type-side-effects
'@typescript-eslint/no-import-type-side-effects': ERROR,

// This rule deals with merging multiple imports from the same module.
// In this case, we want type imports to be inlined when merging with the other imports.
// However, there is a pending PR which improves the behaviour of this rule https://github.com/import-js/eslint-plugin-import/pull/2716
// https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-duplicates.md#inline-type-imports
'import-x/no-duplicates': [ERROR, { 'prefer-inline': true }],
},
// This rule deals with merging multiple imports from the same module.
// In this case, we want type imports to be inlined when merging with the other imports.
// However, there is a pending PR which improves the behaviour of this rule https://github.com/import-js/eslint-plugin-import/pull/2716
// https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-duplicates.md#inline-type-imports
'import-x/no-duplicates': [ERROR, { 'prefer-inline': true }],
},
{
// JavaScript config
},
...compat
.extends('plugin:import-x/errors', 'plugin:import-x/warnings')
.map((config) => ({
...config,
files: [`**/*.{${jsExtensions}}`],
env: {
es6: true,
},
extends: ['plugin:import-x/errors', 'plugin:import-x/warnings'],
settings,
rules: {
'no-undef': ERROR,
'no-use-before-define': [ERROR, { functions: false }],
'no-unused-expressions': ERROR,
'import-x/no-unresolved': [
ERROR,
{ commonjs: true, amd: true, ignore: ['.svg$', '^file?'] },
],
'import-x/no-duplicates': ERROR,
},
})),
{
files: [`**/*.{${jsExtensions}}`],
languageOptions: {
globals: {},
},
{
// Jest config
files: [
`**/__tests__/**/*.{${allExtensions}}`,
`**/*.@(spec|test).{${allExtensions}}`,
settings,
rules: {
'no-undef': ERROR,
'no-use-before-define': [ERROR, { functions: false }],
'no-unused-expressions': ERROR,
'import-x/no-unresolved': [
ERROR,
{ commonjs: true, amd: true, ignore: ['.svg$', '^file?'] },
],
env: {
jest: true,
'import-x/no-duplicates': ERROR,
},
},
...compat.extends('plugin:jest/recommended').map((config) => ({
...config,
files: [
`**/__tests__/**/*.{${allExtensions}}`,
`**/*.@(spec|test).{${allExtensions}}`,
],
})),
{
files: [
`**/__tests__/**/*.{${allExtensions}}`,
`**/*.@(spec|test).{${allExtensions}}`,
],
plugins: { jest },
languageOptions: {
globals: {
...globals.jest,
},
extends: ['plugin:jest/recommended'],
plugins: ['jest'],
},
{
// Cypress config
files: [`**/cypress/**/*.{${allExtensions}}`],
extends: ['plugin:cypress/recommended'],
env: {
'cypress/globals': true,
},
...compat.extends('plugin:cypress/recommended').map((config) => ({
...config,
files: [`**/cypress/**/*.{${allExtensions}}`],
})),
{
files: [`**/cypress/**/*.{${allExtensions}}`],
plugins: { cypress },
languageOptions: {
globals: {
...cypress.environments.globals.globals,
},
plugins: ['cypress'],
},
],
};

module.exports = baseConfig;
},
];
1 change: 1 addition & 0 deletions eslint.config.base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./base');
1 change: 1 addition & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('.');
Loading

0 comments on commit 3c5f20c

Please sign in to comment.