Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v4 - Drop support for eslint 5/6, prettier 1, node 6/8 #429

Merged
merged 6 commits into from
Aug 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# editorconfig.org
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
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
6 changes: 3 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ module.exports = {
'not-an-aardvark/node',
'plugin:node/recommended',
'plugin:eslint-plugin/recommended',
'prettier'
'prettier',
],
env: { mocha: true },
root: true,
rules: {
'self/prettier': ['error'],
'eslint-plugin/report-message-format': ['error', '^[^a-z].*\\.$']
}
'eslint-plugin/report-message-format': ['error', '^[^a-z].*\\.$'],
},
};
28 changes: 2 additions & 26 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,8 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
eslint-version: [7.x, 6.x, 5.x]
node-version: [16.x, 14.x, 12.x, 10.x, 8.x, 6.x]
test-graphql: [true, false]

exclude:
# eslint 7 does not support node 6 or 8
- eslint-version: 7.x
node-version: 8.x
- eslint-version: 7.x
node-version: 6.x
# eslint 6 does not support node 6
# the version of chalk used in eslint 6 does not support node 8
- eslint-version: 6.x
node-version: 8.x
- eslint-version: 6.x
node-version: 6.x
# @graphql-eslint/eslint-plugin does not support node 6 or 8 or 10
- test-graphql: true
node-version: 10.x
- test-graphql: true
node-version: 8.x
- test-graphql: true
node-version: 6.x
eslint-version: [7.x]
node-version: [16.x, 14.x, 12.x]

steps:
- uses: actions/checkout@v2
Expand All @@ -49,8 +28,5 @@ jobs:
- name: Install
run: yarn install

- if: matrix.test-graphql == true
run: yarn add -D @graphql-eslint/eslint-plugin graphql

- name: Test
run: yarn run test
77 changes: 22 additions & 55 deletions eslint-plugin-prettier.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@
// Requirements
// ------------------------------------------------------------------------------

const fs = require('fs');
const path = require('path');

const {
showInvisibles,
generateDifferences
generateDifferences,
} = require('prettier-linter-helpers');

// ------------------------------------------------------------------------------
Expand Down Expand Up @@ -46,43 +43,21 @@ let prettier;
function reportDifference(context, difference) {
const { operation, offset, deleteText = '', insertText = '' } = difference;
const range = [offset, offset + deleteText.length];
const [start, end] = range.map(index =>
const [start, end] = range.map((index) =>
context.getSourceCode().getLocFromIndex(index)
);

context.report({
messageId: operation,
data: {
deleteText: showInvisibles(deleteText),
insertText: showInvisibles(insertText)
insertText: showInvisibles(insertText),
},
loc: { start, end },
fix: fixer => fixer.replaceTextRange(range, insertText)
fix: (fixer) => fixer.replaceTextRange(range, insertText),
});
}

/**
* Given a filepath, get the nearest path that is a regular file.
* The filepath provided by eslint may be a virtual filepath rather than a file
* on disk. This attempts to transform a virtual path into an on-disk path
* @param {string} filepath
* @returns {string}
*/
function getOnDiskFilepath(filepath) {
try {
if (fs.statSync(filepath).isFile()) {
return filepath;
}
} catch (err) {
// https://github.com/eslint/eslint/issues/11989
if (err.code === 'ENOTDIR') {
return getOnDiskFilepath(path.dirname(filepath));
}
}

return filepath;
}

// ------------------------------------------------------------------------------
// Module Definition
// ------------------------------------------------------------------------------
Expand All @@ -95,15 +70,15 @@ module.exports = {
rules: {
'prettier/prettier': 'error',
'arrow-body-style': 'off',
'prefer-arrow-callback': 'off'
}
}
'prefer-arrow-callback': 'off',
},
},
},
rules: {
prettier: {
meta: {
docs: {
url: 'https://github.com/prettier/eslint-plugin-prettier#options'
url: 'https://github.com/prettier/eslint-plugin-prettier#options',
},
type: 'layout',
fixable: 'code',
Expand All @@ -112,7 +87,7 @@ module.exports = {
{
type: 'object',
properties: {},
additionalProperties: true
additionalProperties: true,
},
{
type: 'object',
Expand All @@ -121,17 +96,17 @@ module.exports = {
fileInfoOptions: {
type: 'object',
properties: {},
additionalProperties: true
}
additionalProperties: true,
},
},
additionalProperties: true
}
additionalProperties: true,
},
],
messages: {
[INSERT]: 'Insert `{{ insertText }}`',
[DELETE]: 'Delete `{{ deleteText }}`',
[REPLACE]: 'Replace `{{ deleteText }}` with `{{ insertText }}`'
}
[REPLACE]: 'Replace `{{ deleteText }}` with `{{ insertText }}`',
},
},
create(context) {
const usePrettierrc =
Expand All @@ -145,9 +120,7 @@ module.exports = {
// file paths. If this is the case then we need to resolve prettier
// config and file info using the on-disk path instead of the virtual
// path.
// See https://github.com/eslint/eslint/issues/11989 for ideas around
// being able to get this value directly from eslint in the future.
const onDiskFilepath = getOnDiskFilepath(filepath);
const onDiskFilepath = context.getPhysicalFilename();
const source = sourceCode.text;

return {
Expand All @@ -161,7 +134,7 @@ module.exports = {

const prettierRcOptions = usePrettierrc
? prettier.resolveConfig.sync(onDiskFilepath, {
editorconfig: true
editorconfig: true,
})
: null;

Expand Down Expand Up @@ -221,13 +194,7 @@ module.exports = {
}

if (filepath === onDiskFilepath && inferParserToBabel) {
// Prettier v1.16.0 renamed the `babylon` parser to `babel`
// Use the modern name if available
const supportBabelParser = prettier
.getSupportInfo()
.languages.some(language => language.parsers.includes('babel'));

initialOptions.parser = supportBabelParser ? 'babel' : 'babylon';
initialOptions.parser = 'babel';
}

const prettierOptions = Object.assign(
Expand Down Expand Up @@ -279,9 +246,9 @@ module.exports = {
reportDifference(context, difference);
}
}
}
},
};
}
}
}
},
},
},
};
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,21 @@
"prettier-linter-helpers": "^1.0.0"
},
"peerDependencies": {
"eslint": ">=5.0.0",
"prettier": ">=1.13.0"
"eslint": ">=7.28.0",
"prettier": ">=2.0.0"
},
"devDependencies": {
"@graphql-eslint/eslint-plugin": "^2.0.1",
"@not-an-aardvark/node-release-script": "^0.1.0",
"eslint": "^7.0.0",
"eslint": "^7.28.0",
"eslint-config-not-an-aardvark": "^2.1.0",
"eslint-config-prettier": "^6.0.0",
"eslint-plugin-eslint-plugin": "^2.0.0",
"eslint-plugin-node": "^8.0.0",
"eslint-plugin-self": "^1.1.0",
"graphql": "^15.5.1",
"mocha": "^6.0.0",
"prettier": "^1.15.3",
"prettier": "^2.3.0",
"vue-eslint-parser": "^6.0.0"
},
"peerDependenciesMeta": {
Expand Down
4 changes: 2 additions & 2 deletions test/invalid/10.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
CODE:
var a = {
b: 1
b: 1,
};

OUTPUT:
var a = {
b: 1
b: 1,
};

OPTIONS:
Expand Down
6 changes: 3 additions & 3 deletions test/invalid/11-a.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var a = {

OUTPUT:
var a = {
b: ""
b: "",
};

OPTIONS:
Expand All @@ -14,7 +14,7 @@ OPTIONS:
ERRORS:
[
{
message: 'Replace `\'\',` with `""`',
line: 2, column: 6, endLine: 2, endColumn: 9,
message: 'Replace `\'\'` with `""`',
line: 2, column: 6, endLine: 2, endColumn: 8,
},
]
6 changes: 3 additions & 3 deletions test/invalid/11-b.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var a = {

OUTPUT:
var a = {
b: ""
b: "",
};

OPTIONS:
Expand All @@ -14,7 +14,7 @@ OPTIONS:
ERRORS:
[
{
message: 'Replace `\'\',` with `""`',
line: 2, column: 6, endLine: 2, endColumn: 9,
message: 'Replace `\'\'` with `""`',
line: 2, column: 6, endLine: 2, endColumn: 8,
},
]
20 changes: 20 additions & 0 deletions test/invalid/graphql.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
CODE:
type Query {
foo: String!
}

OUTPUT:
type Query {
foo: String!
}

OPTIONS:
[]

ERRORS:
[
{
message: 'Insert `··`',
line: 2, column: 1, endLine: 2, endColumn: 1,
},
]
Loading