Skip to content

Commit

Permalink
chore: enable some linter rules and tools (#478)
Browse files Browse the repository at this point in the history
  • Loading branch information
JounQin committed Jun 29, 2022
1 parent 34cc896 commit 93facfb
Show file tree
Hide file tree
Showing 23 changed files with 8,823 additions and 2,668 deletions.
3 changes: 3 additions & 0 deletions .commitlintrc
@@ -0,0 +1,3 @@
{
"extends": "@1stg"
}
21 changes: 5 additions & 16 deletions .editorconfig
@@ -1,21 +1,10 @@
# editorconfig.org
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
indent_size = 2
tab_width = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true

# Markdown syntax specifies that trailing whitespaces can be meaningful,
# so let’s not trim those. e.g. 2 trailing spaces = linebreak (<br />)
# See https://daringfireball.net/projects/markdown/syntax#p
[*.md]
trim_trailing_whitespace = false

# Disable trailing whitespace removal in diff files,
# where whitespace is meaningful
[*.diff]
trim_trailing_whitespace = false
insert_final_newline = true
1 change: 0 additions & 1 deletion .eslintignore
@@ -1,2 +1 @@
!.eslintrc.js
test/fixtures
17 changes: 0 additions & 17 deletions .eslintrc.js

This file was deleted.

25 changes: 25 additions & 0 deletions .eslintrc.json
@@ -0,0 +1,25 @@
{
"root": true,
"env": {
"mocha": true
},
"extends": [
"plugin:n/recommended",
"plugin:sonar/recommended",
"plugin:sonarjs/recommended",
"plugin:eslint-plugin/recommended",
"prettier"
],
"plugins": [
"self"
],
"rules": {
"self/prettier": [
"error"
],
"eslint-plugin/report-message-format": [
"error",
"^[^a-z].*\\.$"
]
}
}
1 change: 1 addition & 0 deletions .gitattributes
@@ -0,0 +1 @@
* text=auto eol=lf
4 changes: 2 additions & 2 deletions .github/dependabot.yml
Expand Up @@ -5,9 +5,9 @@ updates:
schedule:
interval: monthly
ignore:
# We're deliberatly targeting heavy backwards compatability to avoid
# We're deliberately targeting heavy backwards compatibility to avoid
# making a breaking change and causing churn for the sake of it.
# Ignore dependencies that would result in or requre a breaking change
# Ignore dependencies that would result in or require a breaking change
- dependency-name: 'eslint'
- dependency-name: 'eslint-*'
- dependency-name: 'prettier'
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Expand Up @@ -16,9 +16,9 @@ jobs:
- 7
- 8
node-version:
- 12
- 14
- 16
- 18

steps:
- uses: actions/checkout@v3
Expand All @@ -27,6 +27,7 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: yarn

- name: Use ESLint ${{ matrix.eslint-version }}
run: yarn upgrade eslint@${{ matrix.eslint-version }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pkg-size.yml
Expand Up @@ -18,7 +18,7 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: 16.x
cache: yarn --frozen-lockfile
cache: yarn

- name: Package Size Report
uses: pkg-size/action@v1
Expand Down
5 changes: 3 additions & 2 deletions .gitignore
@@ -1,2 +1,3 @@
node_modules/
npm-debug.log
node_modules
*.log
.*cache
1 change: 1 addition & 0 deletions .lintstagedrc.js
@@ -0,0 +1 @@
module.exports = require('@1stg/lint-staged');
1 change: 1 addition & 0 deletions .nvmrc
@@ -0,0 +1 @@
lts/*
3 changes: 0 additions & 3 deletions .prettierignore
@@ -1,6 +1,3 @@
package.json
CHANGELOG.md

# this file doesn't exist, but we use it as a filename that should be ignored
# by prettier in the tests
ignore-me.js
4 changes: 1 addition & 3 deletions .prettierrc
@@ -1,3 +1 @@
{
"singleQuote": true
}
"@1stg/prettier-config/semi"
1 change: 1 addition & 0 deletions .simple-git-hooks.js
@@ -0,0 +1 @@
module.exports = require('@1stg/simple-git-hooks');
11 changes: 0 additions & 11 deletions .vscode/settings.json

This file was deleted.

366 changes: 183 additions & 183 deletions CHANGELOG.md

Large diffs are not rendered by default.

20 changes: 9 additions & 11 deletions CONTRIBUTING.md
Expand Up @@ -4,32 +4,30 @@ Thanks for contributing!

## Installation

```bash
```sh
git clone https://github.com/prettier/eslint-plugin-prettier.git
cd eslint-plugin-prettier
yarn # or `npm install`
yarn
```

## Running the tests

```bash
npm test
```sh
yarn test
```

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.

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`.
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`.

## Commit messages

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).
Please view [commitlint](https://commitlint.js.org) for more details.

## Publishing

```bash
npm run generate-release
git push --follow-tags
npm publish
```sh
yarn release
```

`npm run generate-release` will autogenerate a commit, changelog entry, and git tag like https://github.com/prettier/eslint-plugin-prettier/commit/56873bf2.
Please view [changesets](https://github.com/changesets/changesets) and its [action](https://github.com/changesets/action) for more details.
8 changes: 8 additions & 0 deletions README.md
Expand Up @@ -148,3 +148,11 @@ If you’re fixing large of amounts of previously unformatted code, consider tem
## Contributing

See [CONTRIBUTING.md](https://github.com/prettier/eslint-plugin-prettier/blob/master/CONTRIBUTING.md)

## Changelog

Detailed changes for each release are documented in [CHANGELOG.md](./CHANGELOG.md).

## License

[MIT](http://opensource.org/licenses/MIT)
38 changes: 19 additions & 19 deletions eslint-plugin-prettier.js
@@ -1,5 +1,5 @@
/**
* @fileoverview Runs `prettier` as an ESLint rule.
* @file Runs `prettier` as an ESLint rule.
* @author Andres Suarez
*/

Expand Down Expand Up @@ -36,15 +36,16 @@ let prettier;

/**
* Reports a difference.
*
* @param {import('eslint').Rule.RuleContext} context - The ESLint rule context.
* @param {import('prettier-linter-helpers').Difference} difference - The difference object.
* @returns {void}
*/
function reportDifference(context, difference) {
const { operation, offset, deleteText = '', insertText = '' } = difference;
const range = [offset, offset + deleteText.length];
const [start, end] = range.map((index) =>
context.getSourceCode().getLocFromIndex(index)
const [start, end] = range.map(index =>
context.getSourceCode().getLocFromIndex(index),
);

context.report({
Expand All @@ -54,7 +55,7 @@ function reportDifference(context, difference) {
insertText: showInvisibles(insertText),
},
loc: { start, end },
fix: (fixer) => fixer.replaceTextRange(range, insertText),
fix: fixer => fixer.replaceTextRange(range, insertText),
});
}

Expand Down Expand Up @@ -124,6 +125,7 @@ module.exports = {
const source = sourceCode.text;

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

const { ignored, inferredParser } = prettier.getFileInfo.sync(
onDiskFilepath,
Object.assign(
{},
{ resolveConfig: true, ignorePath: '.prettierignore' },
eslintFileInfoOptions
)
{
resolveConfig: true,
ignorePath: '.prettierignore',
...eslintFileInfoOptions,
},
);

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

let inferParserToBabel =
parserBlocklist.indexOf(inferredParser) !== -1;
let inferParserToBabel = parserBlocklist.includes(inferredParser);

if (
// it could be processed by `@graphql-eslint/eslint-plugin` or `eslint-plugin-graphql`
Expand Down Expand Up @@ -223,18 +224,17 @@ module.exports = {
'mdx',
'angular',
];
if (parserBlocklist.indexOf(inferredParser) !== -1) {
if (parserBlocklist.includes(inferredParser)) {
return;
}
}

const prettierOptions = Object.assign(
{},
initialOptions,
prettierRcOptions,
eslintPrettierOptions,
{ filepath }
);
const prettierOptions = {
...initialOptions,
...prettierRcOptions,
...eslintPrettierOptions,
filepath,
};

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

0 comments on commit 93facfb

Please sign in to comment.