Skip to content

Commit 93facfb

Browse files
authored
chore: enable some linter rules and tools (#478)
1 parent 34cc896 commit 93facfb

23 files changed

+8823
-2668
lines changed

.commitlintrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "@1stg"
3+
}

.editorconfig

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,10 @@
1-
# editorconfig.org
21
root = true
32

43
[*]
5-
charset = utf-8
6-
end_of_line = lf
7-
indent_size = 2
84
indent_style = space
9-
insert_final_newline = true
5+
indent_size = 2
6+
tab_width = 2
7+
end_of_line = lf
8+
charset = utf-8
109
trim_trailing_whitespace = true
11-
12-
# Markdown syntax specifies that trailing whitespaces can be meaningful,
13-
# so let’s not trim those. e.g. 2 trailing spaces = linebreak (<br />)
14-
# See https://daringfireball.net/projects/markdown/syntax#p
15-
[*.md]
16-
trim_trailing_whitespace = false
17-
18-
# Disable trailing whitespace removal in diff files,
19-
# where whitespace is meaningful
20-
[*.diff]
21-
trim_trailing_whitespace = false
10+
insert_final_newline = true

.eslintignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
!.eslintrc.js
21
test/fixtures

.eslintrc.js

Lines changed: 0 additions & 17 deletions
This file was deleted.

.eslintrc.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"root": true,
3+
"env": {
4+
"mocha": true
5+
},
6+
"extends": [
7+
"plugin:n/recommended",
8+
"plugin:sonar/recommended",
9+
"plugin:sonarjs/recommended",
10+
"plugin:eslint-plugin/recommended",
11+
"prettier"
12+
],
13+
"plugins": [
14+
"self"
15+
],
16+
"rules": {
17+
"self/prettier": [
18+
"error"
19+
],
20+
"eslint-plugin/report-message-format": [
21+
"error",
22+
"^[^a-z].*\\.$"
23+
]
24+
}
25+
}

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto eol=lf

.github/dependabot.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ updates:
55
schedule:
66
interval: monthly
77
ignore:
8-
# We're deliberatly targeting heavy backwards compatability to avoid
8+
# We're deliberately targeting heavy backwards compatibility to avoid
99
# making a breaking change and causing churn for the sake of it.
10-
# Ignore dependencies that would result in or requre a breaking change
10+
# Ignore dependencies that would result in or require a breaking change
1111
- dependency-name: 'eslint'
1212
- dependency-name: 'eslint-*'
1313
- dependency-name: 'prettier'

.github/workflows/ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ jobs:
1616
- 7
1717
- 8
1818
node-version:
19-
- 12
2019
- 14
2120
- 16
21+
- 18
2222

2323
steps:
2424
- uses: actions/checkout@v3
@@ -27,6 +27,7 @@ jobs:
2727
uses: actions/setup-node@v3
2828
with:
2929
node-version: ${{ matrix.node-version }}
30+
cache: yarn
3031

3132
- name: Use ESLint ${{ matrix.eslint-version }}
3233
run: yarn upgrade eslint@${{ matrix.eslint-version }}

.github/workflows/pkg-size.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
uses: actions/setup-node@v3
1919
with:
2020
node-version: 16.x
21-
cache: yarn --frozen-lockfile
21+
cache: yarn
2222

2323
- name: Package Size Report
2424
uses: pkg-size/action@v1

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
node_modules/
2-
npm-debug.log
1+
node_modules
2+
*.log
3+
.*cache

.lintstagedrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('@1stg/lint-staged');

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lts/*

.prettierignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
package.json
2-
CHANGELOG.md
3-
41
# this file doesn't exist, but we use it as a filename that should be ignored
52
# by prettier in the tests
63
ignore-me.js

.prettierrc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
{
2-
"singleQuote": true
3-
}
1+
"@1stg/prettier-config/semi"

.simple-git-hooks.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('@1stg/simple-git-hooks');

.vscode/settings.json

Lines changed: 0 additions & 11 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 183 additions & 183 deletions
Large diffs are not rendered by default.

CONTRIBUTING.md

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,30 @@ Thanks for contributing!
44

55
## Installation
66

7-
```bash
7+
```sh
88
git clone https://github.com/prettier/eslint-plugin-prettier.git
99
cd eslint-plugin-prettier
10-
yarn # or `npm install`
10+
yarn
1111
```
1212

1313
## Running the tests
1414

15-
```bash
16-
npm test
15+
```sh
16+
yarn test
1717
```
1818

1919
This is an [ESLint](http://eslint.org) plugin. Documentation for the APIs that it uses can be found on ESLint's [Working with Plugins](http://eslint.org/docs/developer-guide/working-with-plugins) page.
2020

21-
This plugin is used to lint itself. The style is checked when `npm test` is run, and the build will fail if there are any linting errors. You can use `npm run lint -- --fix` to fix some linting errors. To run the tests without running the linter, you can use `node_modules/.bin/mocha`.
21+
This plugin is used to lint itself. The style is checked when `yarn test` is run, and the build will fail if there are any linting errors. You can use `yarn lint --fix` to fix some linting errors. To run the tests without running the linter, you can use `yarn mocha`.
2222

2323
## Commit messages
2424

25-
Commit messages should start with one of the following prefixes: `Breaking:`, `New:`, `Update:`, `Fix:`, `Docs:`, `Build:`, `Upgrade:`, `Chore:`. These prefixes are automatically used to determine the release type when generating a release, as described [here](https://github.com/not-an-aardvark/node-release-script/tree/5f5ed3fdfbb584f2e940daab1e2ad948b186410a#what-does-it-do).
25+
Please view [commitlint](https://commitlint.js.org) for more details.
2626

2727
## Publishing
2828

29-
```bash
30-
npm run generate-release
31-
git push --follow-tags
32-
npm publish
29+
```sh
30+
yarn release
3331
```
3432

35-
`npm run generate-release` will autogenerate a commit, changelog entry, and git tag like https://github.com/prettier/eslint-plugin-prettier/commit/56873bf2.
33+
Please view [changesets](https://github.com/changesets/changesets) and its [action](https://github.com/changesets/action) for more details.

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,11 @@ If you’re fixing large of amounts of previously unformatted code, consider tem
148148
## Contributing
149149

150150
See [CONTRIBUTING.md](https://github.com/prettier/eslint-plugin-prettier/blob/master/CONTRIBUTING.md)
151+
152+
## Changelog
153+
154+
Detailed changes for each release are documented in [CHANGELOG.md](./CHANGELOG.md).
155+
156+
## License
157+
158+
[MIT](http://opensource.org/licenses/MIT)

eslint-plugin-prettier.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @fileoverview Runs `prettier` as an ESLint rule.
2+
* @file Runs `prettier` as an ESLint rule.
33
* @author Andres Suarez
44
*/
55

@@ -36,15 +36,16 @@ let prettier;
3636

3737
/**
3838
* Reports a difference.
39+
*
3940
* @param {import('eslint').Rule.RuleContext} context - The ESLint rule context.
4041
* @param {import('prettier-linter-helpers').Difference} difference - The difference object.
4142
* @returns {void}
4243
*/
4344
function reportDifference(context, difference) {
4445
const { operation, offset, deleteText = '', insertText = '' } = difference;
4546
const range = [offset, offset + deleteText.length];
46-
const [start, end] = range.map((index) =>
47-
context.getSourceCode().getLocFromIndex(index)
47+
const [start, end] = range.map(index =>
48+
context.getSourceCode().getLocFromIndex(index),
4849
);
4950

5051
context.report({
@@ -54,7 +55,7 @@ function reportDifference(context, difference) {
5455
insertText: showInvisibles(insertText),
5556
},
5657
loc: { start, end },
57-
fix: (fixer) => fixer.replaceTextRange(range, insertText),
58+
fix: fixer => fixer.replaceTextRange(range, insertText),
5859
});
5960
}
6061

@@ -124,6 +125,7 @@ module.exports = {
124125
const source = sourceCode.text;
125126

126127
return {
128+
// eslint-disable-next-line sonarjs/cognitive-complexity
127129
Program() {
128130
if (!prettier) {
129131
// Prettier is expensive to load, so only load it if needed.
@@ -140,11 +142,11 @@ module.exports = {
140142

141143
const { ignored, inferredParser } = prettier.getFileInfo.sync(
142144
onDiskFilepath,
143-
Object.assign(
144-
{},
145-
{ resolveConfig: true, ignorePath: '.prettierignore' },
146-
eslintFileInfoOptions
147-
)
145+
{
146+
resolveConfig: true,
147+
ignorePath: '.prettierignore',
148+
...eslintFileInfoOptions,
149+
},
148150
);
149151

150152
// Skip if file is ignored using a .prettierignore file
@@ -189,8 +191,7 @@ module.exports = {
189191
// 3. `eslint-plugin-html`
190192
const parserBlocklist = [null, 'markdown', 'html'];
191193

192-
let inferParserToBabel =
193-
parserBlocklist.indexOf(inferredParser) !== -1;
194+
let inferParserToBabel = parserBlocklist.includes(inferredParser);
194195

195196
if (
196197
// it could be processed by `@graphql-eslint/eslint-plugin` or `eslint-plugin-graphql`
@@ -223,18 +224,17 @@ module.exports = {
223224
'mdx',
224225
'angular',
225226
];
226-
if (parserBlocklist.indexOf(inferredParser) !== -1) {
227+
if (parserBlocklist.includes(inferredParser)) {
227228
return;
228229
}
229230
}
230231

231-
const prettierOptions = Object.assign(
232-
{},
233-
initialOptions,
234-
prettierRcOptions,
235-
eslintPrettierOptions,
236-
{ filepath }
237-
);
232+
const prettierOptions = {
233+
...initialOptions,
234+
...prettierRcOptions,
235+
...eslintPrettierOptions,
236+
filepath,
237+
};
238238

239239
// prettier.format() may throw a SyntaxError if it cannot parse the
240240
// source code it is given. Usually for JS files this isn't a

0 commit comments

Comments
 (0)