Skip to content

Commit

Permalink
Breaking: Drop support for ESLint v3 and v4
Browse files Browse the repository at this point in the history
ESLint v5.0.0 is the minimum supported version
  • Loading branch information
BPScott authored and not-an-aardvark committed Oct 1, 2018
1 parent 1ec94c8 commit 2326231
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 95 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ node_js:
env:
- ESLINT_VERSION=current
- ESLINT_VERSION=^5
- ESLINT_VERSION=^4
- ESLINT_VERSION=^3
install:
- if [[ $ESLINT_VERSION != "current" ]]; then
yarn upgrade "eslint@$ESLINT_VERSION";
Expand Down
52 changes: 7 additions & 45 deletions eslint-plugin-prettier.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,46 +41,6 @@ let prettier;
// Helpers
// ------------------------------------------------------------------------------

/**
* Gets the location of a given index in the source code for a given context.
* @param {RuleContext} context - The ESLint rule context.
* @param {number} index - An index in the source code.
* @returns {Object} An object containing numeric `line` and `column` keys.
*/
function getLocFromIndex(context, index) {
// If `sourceCode.getLocFromIndex` is available from ESLint, use it - added
// in ESLint 3.16.0.
const sourceCode = context.getSourceCode();
if (typeof sourceCode.getLocFromIndex === 'function') {
return sourceCode.getLocFromIndex(index);
}
const text = sourceCode.getText();
if (typeof index !== 'number') {
throw new TypeError('Expected `index` to be a number.');
}
if (index < 0 || index > text.length) {
throw new RangeError('Index out of range.');
}
// Loosely based on
// https://github.com/eslint/eslint/blob/18a519fa/lib/ast-utils.js#L408-L438
const lineEndingPattern = /\r\n|[\r\n\u2028\u2029]/g;
let offset = 0;
let line = 0;
let match;
while ((match = lineEndingPattern.exec(text))) {
const next = match.index + match[0].length;
if (index < next) {
break;
}
line++;
offset = next;
}
return {
line: line + 1,
column: index - offset
};
}

/**
* Converts invisible characters to a commonly recognizable visible form.
* @param {string} str - The string with invisibles to convert.
Expand Down Expand Up @@ -225,7 +185,7 @@ function generateDifferences(source, prettierSource) {
* @returns {void}
*/
function reportInsert(context, offset, text) {
const pos = getLocFromIndex(context, offset);
const pos = context.getSourceCode().getLocFromIndex(offset);
const range = [offset, offset];
context.report({
message: 'Insert `{{ code }}`',
Expand All @@ -245,8 +205,8 @@ function reportInsert(context, offset, text) {
* @returns {void}
*/
function reportDelete(context, offset, text) {
const start = getLocFromIndex(context, offset);
const end = getLocFromIndex(context, offset + text.length);
const start = context.getSourceCode().getLocFromIndex(offset);
const end = context.getSourceCode().getLocFromIndex(offset + text.length);
const range = [offset, offset + text.length];
context.report({
message: 'Delete `{{ code }}`',
Expand All @@ -268,8 +228,10 @@ function reportDelete(context, offset, text) {
* @returns {void}
*/
function reportReplace(context, offset, deleteText, insertText) {
const start = getLocFromIndex(context, offset);
const end = getLocFromIndex(context, offset + deleteText.length);
const start = context.getSourceCode().getLocFromIndex(offset);
const end = context
.getSourceCode()
.getLocFromIndex(offset + deleteText.length);
const range = [offset, offset + deleteText.length];
context.report({
message: 'Replace `{{ deleteCode }}` with `{{ insertCode }}`',
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@
"eslint-config-not-an-aardvark": "^2.1.0",
"eslint-config-prettier": "^3.1.0",
"eslint-plugin-eslint-plugin": "^1.4.0",
"eslint-plugin-node": "^6.0.1",
"eslint-plugin-node": "^7.0.1",
"eslint-plugin-self": "^1.1.0",
"mocha": "^5.2.0",
"prettier": "^1.13.0",
"vue-eslint-parser": "^2.0.3"
"vue-eslint-parser": "^3.2.2"
},
"engines": {
"node": ">=6.0.0"
Expand Down
73 changes: 27 additions & 46 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,13 @@
moment "^2.18.1"
semver "^5.4.1"

acorn-jsx@^3.0.0:
version "3.0.1"
resolved "http://registry.npmjs.org/acorn-jsx/-/acorn-jsx-3.0.1.tgz#afdf9488fb1ecefc8348f6fb22f464e32a58b36b"
dependencies:
acorn "^3.0.4"

acorn-jsx@^4.1.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/acorn-jsx/-/acorn-jsx-4.1.1.tgz#e8e41e48ea2fe0c896740610ab6a4ffd8add225e"
dependencies:
acorn "^5.0.3"

acorn@^3.0.4:
version "3.3.0"
resolved "http://registry.npmjs.org/acorn/-/acorn-3.3.0.tgz#45e37fb39e8da3f25baee3ff5369e2bb5f22017a"

acorn@^5.0.3, acorn@^5.5.0, acorn@^5.6.0:
acorn@^5.0.3, acorn@^5.6.0:
version "5.7.3"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.7.3.tgz#67aa231bf8812974b85235a96771eb6bd07ea279"

Expand Down Expand Up @@ -221,38 +211,40 @@ eslint-config-prettier@^3.1.0:
dependencies:
get-stdin "^6.0.0"

eslint-plugin-es@^1.3.1:
version "1.3.1"
resolved "https://registry.yarnpkg.com/eslint-plugin-es/-/eslint-plugin-es-1.3.1.tgz#5acb2565db4434803d1d46a9b4cbc94b345bd028"
dependencies:
eslint-utils "^1.3.0"
regexpp "^2.0.0"

eslint-plugin-eslint-plugin@^1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-eslint-plugin/-/eslint-plugin-eslint-plugin-1.4.0.tgz#382dc6692a741a52072d5f3fff5dacdcf291ef49"

eslint-plugin-node@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/eslint-plugin-node/-/eslint-plugin-node-6.0.1.tgz#bf19642298064379315d7a4b2a75937376fa05e4"
eslint-plugin-node@^7.0.1:
version "7.0.1"
resolved "https://registry.yarnpkg.com/eslint-plugin-node/-/eslint-plugin-node-7.0.1.tgz#a6e054e50199b2edd85518b89b4e7b323c9f36db"
dependencies:
ignore "^3.3.6"
eslint-plugin-es "^1.3.1"
eslint-utils "^1.3.1"
ignore "^4.0.2"
minimatch "^3.0.4"
resolve "^1.3.3"
semver "^5.4.1"
resolve "^1.8.1"
semver "^5.5.0"

eslint-plugin-self@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-self/-/eslint-plugin-self-1.1.0.tgz#e95b26d599f17ca0ef63dbaace8bff13c599eaef"

eslint-scope@^3.7.1:
version "3.7.3"
resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-3.7.3.tgz#bb507200d3d17f60247636160b4826284b108535"
dependencies:
esrecurse "^4.1.0"
estraverse "^4.1.1"

eslint-scope@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-4.0.0.tgz#50bf3071e9338bcdc43331794a0cb533f0136172"
dependencies:
esrecurse "^4.1.0"
estraverse "^4.1.1"

eslint-utils@^1.3.1:
eslint-utils@^1.3.0, eslint-utils@^1.3.1:
version "1.3.1"
resolved "https://registry.yarnpkg.com/eslint-utils/-/eslint-utils-1.3.1.tgz#9a851ba89ee7c460346f97cf8939c7298827e512"

Expand Down Expand Up @@ -303,13 +295,6 @@ eslint@^5.6.0:
table "^4.0.3"
text-table "^0.2.0"

espree@^3.5.2:
version "3.5.4"
resolved "https://registry.yarnpkg.com/espree/-/espree-3.5.4.tgz#b0f447187c8a8bed944b815a660bddf5deb5d1a7"
dependencies:
acorn "^5.5.0"
acorn-jsx "^3.0.0"

espree@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/espree/-/espree-4.0.0.tgz#253998f20a0f82db5d866385799d912a83a36634"
Expand All @@ -321,7 +306,7 @@ esprima@^4.0.0:
version "4.0.1"
resolved "https://registry.yarnpkg.com/esprima/-/esprima-4.0.1.tgz#13b04cdb3e6c5d19df91ab6987a8695619b0aa71"

esquery@^1.0.0, esquery@^1.0.1:
esquery@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/esquery/-/esquery-1.0.1.tgz#406c51658b1f5991a5f9b62b1dc25b00e3e5c708"
dependencies:
Expand Down Expand Up @@ -458,11 +443,7 @@ iconv-lite@^0.4.24:
dependencies:
safer-buffer ">= 2.1.2 < 3"

ignore@^3.3.6:
version "3.3.10"
resolved "https://registry.yarnpkg.com/ignore/-/ignore-3.3.10.tgz#0a97fb876986e8081c631160f8f9f389157f0043"

ignore@^4.0.6:
ignore@^4.0.2, ignore@^4.0.6:
version "4.0.6"
resolved "https://registry.yarnpkg.com/ignore/-/ignore-4.0.6.tgz#750e3db5862087b4737ebac8207ffd1ef27b25fc"

Expand Down Expand Up @@ -717,7 +698,7 @@ resolve-from@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-1.0.1.tgz#26cbfe935d1aeeeabb29bc3fe5aeb01e93d44226"

resolve@^1.3.3:
resolve@^1.8.1:
version "1.8.1"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.8.1.tgz#82f1ec19a423ac1fbd080b0bab06ba36e84a7a26"
dependencies:
Expand Down Expand Up @@ -850,16 +831,16 @@ uri-js@^4.2.2:
dependencies:
punycode "^2.1.0"

vue-eslint-parser@^2.0.3:
version "2.0.3"
resolved "https://registry.yarnpkg.com/vue-eslint-parser/-/vue-eslint-parser-2.0.3.tgz#c268c96c6d94cfe3d938a5f7593959b0ca3360d1"
vue-eslint-parser@^3.2.2:
version "3.2.2"
resolved "https://registry.yarnpkg.com/vue-eslint-parser/-/vue-eslint-parser-3.2.2.tgz#47c971ee4c39b0ee7d7f5e154cb621beb22f7a34"
dependencies:
debug "^3.1.0"
eslint-scope "^3.7.1"
eslint-scope "^4.0.0"
eslint-visitor-keys "^1.0.0"
espree "^3.5.2"
esquery "^1.0.0"
lodash "^4.17.4"
espree "^4.0.0"
esquery "^1.0.1"
lodash "^4.17.10"

which@^1.2.9:
version "1.3.1"
Expand Down

0 comments on commit 2326231

Please sign in to comment.