Skip to content

Commit

Permalink
Fix: Location
Browse files Browse the repository at this point in the history
  • Loading branch information
sarvaje committed Mar 6, 2019
1 parent 0d43dd6 commit e79317f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 17 deletions.
14 changes: 7 additions & 7 deletions packages/hint-compat-api/tests/html-next.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ hintRunner.testHint(hintPath, elementAttrAddedAlwaysTrue, { browserslist: ['> 1%
const elementAttrVersionAddedFalse: HintTest[] = [
{
name: 'Element attributes that have version added as false and not deprecated should fail.',
reports: [{ message: 'srcset attribute of the img element is not supported by ie.', position: { column: 9, line: 5 } }],
reports: [{ message: 'srcset attribute of the img element is not supported by ie.', position: { column: 9, line: 4 } }],
serverConfig: generateHTMLConfig('img-srcset')
}
];
Expand Down Expand Up @@ -87,7 +87,7 @@ hintRunner.testHint(hintPath, elementAddedVersionOfTargetedBrowser, { browsersli
const elementAddedInVersionAfterTargetedBrowserVersion: HintTest[] = [
{
name: 'Elements added in version after targeted browser should fail.',
reports: [{ message: 'video element is not supported by ie 8.', position: { column: 9, line: 5 } }],
reports: [{ message: 'video element is not supported by ie 8.', position: { column: 9, line: 4 } }],
serverConfig: generateHTMLConfig('video')
}
];
Expand Down Expand Up @@ -118,7 +118,7 @@ hintRunner.testHint(hintPath, globalAttrVersionAddedNull, { browserslist: ['last
const globalAttrVersionAddedFalse: HintTest[] = [
{
name: 'Global attributes that have version added as false and not deprecated should fail.',
reports: [{ message: 'global attribute dropzone is not supported by edge, firefox, ie.', position: { column: 9, line: 5 } }],
reports: [{ message: 'global attribute dropzone is not supported by edge, firefox, ie.', position: { column: 9, line: 4 } }],
serverConfig: generateHTMLConfig('global-attr-dropzone')
}
];
Expand Down Expand Up @@ -146,7 +146,7 @@ hintRunner.testHint(hintPath, globalAttrAddedVersionOfTargetedBrowser, { browser
const globalAttrAddedInVersionAfterTargetedBrowserVersion: HintTest[] = [
{
name: 'Global attributes added in version after targeted browser should fail.',
reports: [{ message: 'global attribute class is not supported by firefox 31.', position: { column: 9, line: 5 } }],
reports: [{ message: 'global attribute class is not supported by firefox 31.', position: { column: 9, line: 4 } }],
serverConfig: generateHTMLConfig('div')
}
];
Expand All @@ -169,7 +169,7 @@ hintRunner.testHint(hintPath, inputTypeVersionAddedNull, { browserslist: ['last
const inputTypeVersionAddedFalse: HintTest[] = [
{
name: 'Input types that have version added as false and not deprecated should fail.',
reports: [{ message: 'input type color is not supported by ie.', position: { column: 9, line: 5 } }],
reports: [{ message: 'input type color is not supported by ie.', position: { column: 9, line: 4 } }],
serverConfig: generateHTMLConfig('input-color')
}
];
Expand All @@ -179,7 +179,7 @@ hintRunner.testHint(hintPath, inputTypeVersionAddedFalse, { browserslist: ['ie 9
const inputTypeVersionAddedAfterTargetedBrowsers: HintTest[] = [
{
name: 'Input types added in a version after the targeted browsers should fail.',
reports: [{ message: 'input type color is not supported by chrome 19, firefox 28.', position: { column: 9, line: 5 } }],
reports: [{ message: 'input type color is not supported by chrome 19, firefox 28.', position: { column: 9, line: 4 } }],
serverConfig: generateHTMLConfig('input-color')
}
];
Expand All @@ -193,7 +193,7 @@ hintRunner.testHint(hintPath, inputTypeVersionAddedAfterTargetedBrowsers, { brow
const mixedFeaturedCompatibility: HintTest[] = [
{
name: 'Features with mixed compatibility (not supported for specific version and never supported) and not deprecated should throw errors for browsers in which the feature is not supported.',
reports: [{ message: 'integrity attribute of the link element is not supported by edge, ie, safari, safari_ios, samsunginternet_android 4, webview_android 4.', position: { column: 9, line: 5 } }],
reports: [{ message: 'integrity attribute of the link element is not supported by edge, ie, safari, safari_ios, samsunginternet_android 4, webview_android 4.', position: { column: 9, line: 4 } }],
serverConfig: generateHTMLConfig('link-integrity')
}
];
Expand Down
10 changes: 5 additions & 5 deletions packages/hint-compat-api/tests/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ hintRunner.testHint(hintPath, removedForFlags, { browserslist: ['firefox 34'] })
const onlySupportedByFlags: HintTest[] = [
{
name: 'Elements only supported by flags should fail.',
reports: [{ message: 'shadow element is not supported by firefox 60.', position: { column: 9, line: 5 } }],
reports: [{ message: 'shadow element is not supported by firefox 60.', position: { column: 9, line: 4 } }],
serverConfig: generateHTMLConfig('shadow')
}
];
Expand Down Expand Up @@ -99,7 +99,7 @@ hintRunner.testHint(hintPath, elementRemovedVersionEarlierThanTargetedBrowser, {
const elementVersionAddedFalse: HintTest[] = [
{
name: 'Elements that have version added as false should fail.',
reports: [{ message: 'blink element is not supported by chrome.', position: { column: 9, line: 5 } }],
reports: [{ message: 'blink element is not supported by chrome.', position: { column: 9, line: 4 } }],
serverConfig: generateHTMLConfig('blink')
}
];
Expand All @@ -109,7 +109,7 @@ hintRunner.testHint(hintPath, elementVersionAddedFalse, { browserslist: ['last 2
const featureVersionAddedFalseForAllTargetedBrowsers: HintTest[] = [
{
name: 'Features with no support (version added is false) for multiple targeted browsers should fail.',
reports: [{ message: 'element element is not supported by any of your target browsers.', position: { column: 9, line: 5 } }],
reports: [{ message: 'element element is not supported by any of your target browsers.', position: { column: 9, line: 4 } }],
serverConfig: generateHTMLConfig('element')
}
];
Expand All @@ -119,7 +119,7 @@ hintRunner.testHint(hintPath, featureVersionAddedFalseForAllTargetedBrowsers, {
const elementVersionAddedFalseForMultipleBrowsers: HintTest[] = [
{
name: 'Elements that have version added as false for multiple browsers should fail with one error.',
reports: [{ message: 'blink element is not supported by chrome, edge, ie.', position: { column: 9, line: 5 } }],
reports: [{ message: 'blink element is not supported by chrome, edge, ie.', position: { column: 9, line: 4 } }],
serverConfig: generateHTMLConfig('blink')
}
];
Expand All @@ -129,7 +129,7 @@ hintRunner.testHint(hintPath, elementVersionAddedFalseForMultipleBrowsers, { bro
const featureVersionAddedMixedFalseAndNullForDifferentBrowsers: HintTest[] = [
{
name: 'Features with unknown support (version added is null) and no support (version added is false) for different browsers should fail for unsupported browsers.',
reports: [{ message: 'element element is not supported by edge, firefox_android.', position: { column: 9, line: 5 } }],
reports: [{ message: 'element element is not supported by edge, firefox_android.', position: { column: 9, line: 4 } }],
serverConfig: generateHTMLConfig('element')
}
];
Expand Down
6 changes: 3 additions & 3 deletions packages/hint-no-protocol-relative-urls/tests/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const tests: HintTest[] = [
name: `'link' with initial // fails the hint`,
reports: [{
message: generateErrorMessage('//site.webmanifest'),
position: { column: 9, line: 2 }
position: { column: 9, line: 1 }
}],
serverConfig: generateHTMLPage('<link rel="manifest" href="//site.webmanifest">')
},
Expand All @@ -46,7 +46,7 @@ const tests: HintTest[] = [
name: `'script' with initial // fails the hint`,
reports: [{
message: generateErrorMessage('//script.js'),
position: { column: 9, line: 5 }
position: { column: 9, line: 4 }
}],
serverConfig: generateHTMLPage(undefined, '<script src="//script.js"></script>')
},
Expand All @@ -66,7 +66,7 @@ const tests: HintTest[] = [
name: `'a' with initial // fails the hint`,
reports: [{
message: generateErrorMessage('//home'),
position: { column: 9, line: 5 }
position: { column: 9, line: 4 }
}],
serverConfig: generateHTMLPage(undefined, '<a href="//home">home</a>')
},
Expand Down
6 changes: 5 additions & 1 deletion packages/hint/src/lib/types/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,16 @@ export class HTMLElement {
return value;
}

/**
* zero-based location of the element.
*/
public getLocation(): ProblemLocation {
const location = this._element.sourceCodeLocation;

return {
// Column is zero-based, but pointing to the tag name, not the character <
column: location.startCol,
line: location.startLine
line: location.startLine - 1
};
}

Expand Down
2 changes: 1 addition & 1 deletion packages/hint/tests/lib/types/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ test('HTMLElement.getLocation() should return the element location', (t) => {
const item = t.context.document.querySelectorAll('.title')[0];
const location = item.getLocation();

t.is(location.line, 4);
t.is(location.line, 3);
t.is(location.column, 9);
});

Expand Down

0 comments on commit e79317f

Please sign in to comment.