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

remove given/when/then specific indentation rule #50

Merged
merged 1 commit into from
Jun 1, 2019
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
2 changes: 1 addition & 1 deletion src/formatters/stylish.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const stylizeRuleErrorWith = (maxErrorMsgLength, maxLineChars) => (error) => {
let str = ' '; // indent 2 spaces so it looks pretty
const padding = ' '; // padding of 4 spaces, will be used between line numbers, error msgs and rule names
let {line} = error.location;
line = line ? line.toString() : '';
line = line.toString();

// add spaces until the line string is as long as our longest line string
while (line.length < maxLineChars) {
Expand Down
22 changes: 2 additions & 20 deletions src/rules/indentation.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ const defaultConfig = {
'Step': 2,
'Examples': 0,
'example': 2,
'given': 2,
'when': 2,
'then': 2,
'and': 2,
'but': 2,
'DocString': 4,
};

Expand Down Expand Up @@ -93,10 +88,6 @@ const checkTags = (testNode) => (node) => {
return flatMap(compose(testNode, getFirstTag))(tagsPerLine);
};

const findKey = (obj, predicate) => {
return Object.keys(obj).find((key) => predicate(obj[key]));
};

const testDocString = (parseDocString, test) => (step) => {
if (!step.argument || step.argument.type !== 'DocString') {
return [];
Expand All @@ -109,16 +100,8 @@ const testDocString = (parseDocString, test) => (step) => {
return docString.lines.map(test('DocString line'));
};

const getStepType = (feature, languageKeywords, config) => (step) => {
const keyword = step.keyword;
const stepType = findKey(languageKeywords, (values) => {
return values instanceof Array && values.indexOf(keyword) !== -1;
});
return stepType in config ? stepType : 'Step';
};

const testStep = (getStepType, testDocstring, testNode) => (step) => {
const stepType = getStepType(step);
const testStep = (testDocstring, testNode) => (step) => {
const stepType = step.type;
return applyOver([
testNode(stepType),
testDocstring,
Expand Down Expand Up @@ -168,7 +151,6 @@ const run = ({feature, languageKeywords, file, config}) => {

return testFeature(
testStep(
getStepType(feature, languageKeywords, config),
testDocString(parseDocString(lines), test),
test
),
Expand Down
5 changes: 0 additions & 5 deletions src/utils/generic.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ const reduce = (reducer, acc) => (input) => {
if (Array.isArray(input)) {
return input.reduce(reducer, acc);
}
for (const name in input) {
if (({}).hasOwnProperty.call(input, name)) {
acc = reducer(acc, input[name]);
}
}
return acc;
};

Expand Down
2 changes: 0 additions & 2 deletions test/rules-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ describe('Rule Parser', function() {
'Background': 1,
'Scenario': 1,
'Step': 1,
'given': 1,
'and': 1,
}],
});
return hasRules(rulesOrErrors, []);
Expand Down
33 changes: 4 additions & 29 deletions test/rules/indentation/indentation.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,19 +115,19 @@ const wrongIndentationErrors = [{
}];

describe('Indentation rule', () => {
it('doesn\'t raise errors when the default conifguration is used and there are no indentation violations (spaces)', () => {
it('does not raise errors when the default conifguration is used and there are no indentation violations (spaces)', () => {
return runTest('indentation/CorrectIndentationSpaces.feature', {}, []);
});

it('doesn\'t raise errors when scenario outline does not have examples', () => {
it('does not raise errors when scenario outline does not have examples', () => {
return runTest('indentation/CorrectIndentationWithoutExamples.feature', {}, []);
});

it('doesn\'t raise errors when the file is empty', () => {
it('does not raise errors when the file is empty', () => {
return runTest('Empty.feature', {}, []);
});

it('doesn\'t raise errors when the default conifguration is used are and there no indentation violations (tabs)', () => {
it('does not raise errors when the default conifguration is used are and there no indentation violations (tabs)', () => {
return runTest('indentation/CorrectIndentationTabs.feature', {}, []);
});

Expand Down Expand Up @@ -261,31 +261,6 @@ describe('Indentation rule', () => {
}, []);
});

it('Wrong "then" step in customized configuration', () => {
return runTest('indentation/WrongSteps.feature', {
Feature: 1,
Background: 4,
Scenario: 1,
Examples: 2,
example: 4,
then: 0,
}, [{
message: message({element: 'then', expected: 0, actual: 3}),
rule: ruleName,
location: {
line: 7,
column: 4,
},
}, {
message: message({element: 'then', expected: 0, actual: 5}),
rule: ruleName,
location: {
line: 12,
column: 6,
},
}]);
});

context('DocString', () => {
it('Correct indentation', () => {
return runTest('indentation/CorrectIndentationDocStrings.feature', {
Expand Down