Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Commit

Permalink
Fix #128 by guarding wrap-guide-enablement by activation-check (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
florianb committed Nov 1, 2016
1 parent e17fd59 commit 95d49fa
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 16 deletions.
3 changes: 2 additions & 1 deletion index.js
Expand Up @@ -110,7 +110,8 @@ function initializeTextBuffer(buffer) {

// Sets the given package active or inactive
setPackageState(name, active) {
if (atom.packages.isPackageActive(name) !== active) {
if (atom.packages.isPackageDisabled(name) === false &&
atom.packages.isPackageActive(name) !== active) {
if (active === true) {
atom.packages.activatePackage(name);
} else {
Expand Down
68 changes: 68 additions & 0 deletions spec/iss128-spec.js
@@ -0,0 +1,68 @@
/** @babel */
/* eslint-env jasmine, atomtest */

/*
This file contains verifying specs for:
https://github.com/sindresorhus/atom-editorconfig/issues/128
To apply the max_line_length-property the wrap-guide-package is being de/activated if needed,
to avoid that two wrap-guides are being displayed at once. The past implementation assumed that
changing the activation-state wouldn't be able to override a package-disablement. It turned out
that the package activation-state must be guarded by a disablement-proof.
*/

import fs from 'fs';
import path from 'path';

const projectRoot = path.join(__dirname, 'fixtures');
const filePath = path.join(
projectRoot,
`test.${path.basename(__filename).split('-').shift()}`
);

describe('editorconfig', () => {
let textEditor;

beforeEach(() => {
waitsForPromise(() =>
Promise.all([
atom.packages.activatePackage('editorconfig'),
atom.packages.disablePackage('wrap-guide'),
atom.workspace.open(filePath)
]).then(results => {
textEditor = results[2];
})
);
});

afterEach(() => {
// remove the created fixture, if it exists
runs(() => {
fs.stat(filePath, (err, stats) => {
if (!err && stats.isFile()) {
fs.unlink(filePath);
}
});
});

waitsFor(() => {
try {
return fs.statSync(filePath).isFile() === false;
} catch (err) {
return true;
}
}, 5000, `removed ${filePath}`);
});

describe('Atom with disabled wrap-guide', () => {
beforeEach(() => {
Object.assign(textEditor.getBuffer().editorconfig.settings, {
max_line_length: 'auto' // eslint-disable-line camelcase
});
});

it('should not activate wrap-guide', () => {
expect(atom.packages.isPackageActive('wrap-guide')).toEqual(false);
});
});
});
29 changes: 14 additions & 15 deletions yarn.lock
Expand Up @@ -498,8 +498,8 @@ eslint-plugin-unicorn@^1.0.0:
req-all "^0.1.0"

eslint@^3.6.0:
version "3.9.0"
resolved "https://registry.yarnpkg.com/eslint/-/eslint-3.9.0.tgz#68c8fa86b1e0a3f038040f3b5808b7508c128f8e"
version "3.9.1"
resolved "https://registry.yarnpkg.com/eslint/-/eslint-3.9.1.tgz#5a8597706fc6048bc6061ac754d4a211d28f4f5b"
dependencies:
babel-code-frame "^6.16.0"
chalk "^1.1.3"
Expand Down Expand Up @@ -712,12 +712,11 @@ globby@^6.0.0:
pinkie-promise "^2.0.0"

got@^5.0.0:
version "5.6.0"
resolved "https://registry.yarnpkg.com/got/-/got-5.6.0.tgz#bb1d7ee163b78082bbc8eb836f3f395004ea6fbf"
version "5.7.0"
resolved "https://registry.yarnpkg.com/got/-/got-5.7.0.tgz#718879e60f824cc0f69721127b835379b056a3af"
dependencies:
create-error-class "^3.0.1"
duplexer2 "^0.1.4"
is-plain-obj "^1.0.0"
is-redirect "^1.0.0"
is-retry-allowed "^1.0.0"
is-stream "^1.0.0"
Expand All @@ -728,8 +727,8 @@ got@^5.0.0:
pinkie-promise "^2.0.0"
read-all-stream "^3.0.0"
readable-stream "^2.0.5"
timed-out "^2.0.0"
unzip-response "^1.0.0"
timed-out "^3.0.0"
unzip-response "^1.0.2"
url-parse-lax "^1.0.0"

graceful-fs@^4.1.2:
Expand Down Expand Up @@ -1039,8 +1038,8 @@ lodash.upperfirst@^4.2.0:
resolved "https://registry.yarnpkg.com/lodash.upperfirst/-/lodash.upperfirst-4.3.1.tgz#1365edf431480481ef0d1c68957a5ed99d49f7ce"

lodash@^4.0.0, lodash@^4.13.1, lodash@^4.3.0:
version "4.16.5"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.16.5.tgz#77d88feac548009b1a5c4ca7b49ac431ce346ae8"
version "4.16.6"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.16.6.tgz#d22c9ac660288f3843e16ba7d2b5d06cca27d777"

log-symbols@^1.0.2:
version "1.0.2"
Expand Down Expand Up @@ -1618,9 +1617,9 @@ through@^2.3.6:
version "2.3.8"
resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5"

timed-out@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/timed-out/-/timed-out-2.0.0.tgz#f38b0ae81d3747d628001f41dafc652ace671c0a"
timed-out@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/timed-out/-/timed-out-3.0.0.tgz#ff88de96030ce960eabd42487db61d3add229273"

trim-newlines@^1.0.0:
version "1.0.0"
Expand All @@ -1640,9 +1639,9 @@ typedarray@~0.0.5:
version "0.0.6"
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"

unzip-response@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/unzip-response/-/unzip-response-1.0.1.tgz#4a73959f2989470fa503791cefb54e1dbbc68412"
unzip-response@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/unzip-response/-/unzip-response-1.0.2.tgz#b984f0877fc0a89c2c773cc1ef7b5b232b5b06fe"

update-notifier@^1.0.0:
version "1.0.2"
Expand Down

0 comments on commit 95d49fa

Please sign in to comment.