Skip to content

Commit

Permalink
🎨 Reformat README (#5)
Browse files Browse the repository at this point in the history
Reformats README with sentence-based line breaks. Replaces Prettier
config file with `.editorconfig`. Adds early version of functional form
for export alongside default export.
  • Loading branch information
connorjs authored May 27, 2024
1 parent 160ea33 commit d192257
Show file tree
Hide file tree
Showing 8 changed files with 224 additions and 245 deletions.
7 changes: 7 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[*]
charset = utf-8
end_of_line = lf
indent_size = 2
# https://alexandersandberg.com/articles/default-to-tabs-instead-of-spaces-for-an-accessible-first-environment/
indent_style = tab
insert_final_newline = true
261 changes: 107 additions & 154 deletions README.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-config-connorjs",
"version": "1.0.0-alpha.8",
"version": "1.0.0-alpha.9",
"description": "My (@connorjs) preferred ESLint configuration. With ESLint flat config.",
"keywords": [
"eslint",
Expand Down
3 changes: 0 additions & 3 deletions prettier.config.cjs

This file was deleted.

26 changes: 22 additions & 4 deletions src/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,32 @@ import { react } from "./react.js";
*
* @type {import('@typescript-eslint/utils').TSESLint.FlatConfig.ConfigFile}
*/
const config = [
const connorjsConfig = [
...javascriptAndTypescript,
...react,
...json,
...json({ packageJson: true }),
...html,
...graphql,
...base, // Last to apply to all file types
];

// eslint-disable-next-line import/no-default-export -- ESLint configs use default export (community practice)
export default config;
export default connorjsConfig;

/**
* Creates a custom `@connorjs` ESLint config.
*
* @param options - Configuration options.
* @param options.html {boolean=true} - Enables HTML.
* @param options.graphql {boolean=false} - Enables GraphQL.
* @param options.packageJson {boolean=true} - Applies `package.json` sorting rules.
*/
export function createConnorjsConfig(options = {}) {
return [
...javascriptAndTypescript,
...react,
...json({ packageJson: options.packageJson ?? true }),
...(options.html ?? true ? html : []),
...(options.graphql ? graphql : []),
...base, // Last to apply to all file types
];
}
3 changes: 1 addition & 2 deletions src/javascript-and-typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ export const javascriptAndTypescript = tseslint.config(
{
/* eslint-disable unicorn/string-content -- Configuring this rule */
patterns: {
// The quote items can cause controversy, so I’ve
// commented out by default.
// The quote items can cause controversy, so I’ve commented out by default.
//
// '"': {
// fix: false, // Should not fix quotes
Expand Down
163 changes: 84 additions & 79 deletions src/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,90 +2,95 @@ import jsoncPlugin from "eslint-plugin-jsonc";
import jsoncParser from "jsonc-eslint-parser";
import tseslint from "typescript-eslint";

export const json = tseslint.config(
{
// JSON files
files: [`**/*.{json,jsonc}`],
ignores: [`package-lock.json`],
languageOptions: {
parser: jsoncParser,
export function json(options = {}) {
const config = tseslint.config(
{
// JSON files
files: [`**/*.{json,jsonc}`],
ignores: [`package-lock.json`],
languageOptions: {
parser: jsoncParser,
},
plugins: { jsonc: jsoncPlugin },
rules: {
...jsoncPlugin.configs[`recommended-with-json`].rules,
...jsoncPlugin.configs.prettier.rules,
"jsonc/sort-keys": `error`, // Specify per-file orders as needed (below)
},
},
plugins: { jsonc: jsoncPlugin },
rules: {
...jsoncPlugin.configs[`recommended-with-json`].rules,
...jsoncPlugin.configs.prettier.rules,
"jsonc/sort-keys": `error`, // Specify per-file orders as needed (below)
{
// These allow comments (a.k.a. JSONC files)
files: [
`**/global.json`,
`**/tsconfig*.json`,
`**/turbo.json`,
`**/*.jsonc`,
],
rules: { "jsonc/no-comments": `off` },
},
},
{
// These allow comments (a.k.a. JSONC files)
files: [
`**/global.json`,
`**/tsconfig*.json`,
`**/turbo.json`,
`**/*.jsonc`,
],
rules: { "jsonc/no-comments": `off` },
},
{
// Special rules for package.json
files: [`**/package.json`],
rules: {
"jsonc/sort-keys": [
`warn`, // warn because nothing is “wrong” and this config may change often
{
// Defines order of root properties
order: [
`name`,
`version`,
`description`,
`private`,
);
if (options.packageJson) {
config.push({
// Special rules for package.json
files: [`**/package.json`],
rules: {
"jsonc/sort-keys": [
`warn`, // warn because nothing is “wrong” and this config may change often
{
// Defines order of root properties
order: [
`name`,
`version`,
`description`,
`private`,

// Additional publish info
`keywords`,
`homepage`,
`bugs`,
`license`,
`author`,
`repository`,
`publishConfig`,
// End publish info
// Additional publish info
`keywords`,
`homepage`,
`bugs`,
`license`,
`author`,
`repository`,
`publishConfig`,
// End publish info

`type`,
`engines`, // Often used for ESM, so relates to `type`
`type`,
`engines`, // Often used for ESM, so relates to `type`

// Export fields
`bin`,
`directories`,
`files`,
`exports`,
// End export fields
// Export fields
`bin`,
`directories`,
`files`,
`exports`,
// End export fields

`scripts`,
// Tool-specific directly after scripts, alphabetical
`browserslist`,
`eslint`,
`lint-staged`,
// End tool-specific
`scripts`,
// Tool-specific directly after scripts, alphabetical
`browserslist`,
`eslint`,
`lint-staged`,
// End tool-specific

// Dependency related, specific order
`engineStrict`,
`overrides`, // Overrides before dependencies to emphasize their existence
`optionalDependencies`,
`peerDependencies`,
`peerDependenciesMeta`,
`dependencies`,
`devDependencies`,
// End dependency related
// Dependency related, specific order
`engineStrict`,
`overrides`, // Overrides before dependencies to emphasize their existence
`optionalDependencies`,
`peerDependencies`,
`peerDependenciesMeta`,
`dependencies`,
`devDependencies`,
// End dependency related

`workspaces`,
{ order: { type: `desc` } }, // Force other properties to go last
],
pathPattern: `^$`,
},
// Reinstate normal order for non-root properties
{ order: { type: `asc` }, pathPattern: `.*` },
],
},
},
);
`workspaces`,
{ order: { type: `desc` } }, // Force other properties to go last
],
pathPattern: `^$`,
},
// Reinstate normal order for non-root properties
{ order: { type: `asc` }, pathPattern: `.*` },
],
},
});
}
return config;
}

0 comments on commit d192257

Please sign in to comment.