Skip to content

Commit

Permalink
feat(rules): add 'no-get-location-abs-url' rule
Browse files Browse the repository at this point in the history
  • Loading branch information
alecxe committed Jun 22, 2017
1 parent 732977d commit d33f8c8
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ There are various types of rules implemented in the plugin. Here is a rough cate
* [array-callback-return][]: Enforce `return` statements in callbacks of `ElementArrayFinder` methods
* [no-get-inner-outer-html][]: Warn about using deprecated `getInnerHtml()` and `getOuterHtml()` methods
* [no-get-raw-id][]: Warn about using removed `getRawId()` method
* [no-get-location-abs-url][]: Warn about using deprecated `getLocationAbsUrl()` method
* [no-promise-in-if][]: Warn if promise is checked for truthiness inside an `if` condition
#### Locating Elements
Expand Down Expand Up @@ -122,6 +123,7 @@ Rule | Default Error Level | Auto-fixable | Options
[no-get-in-it][] | 1 | |
[array-callback-return][] | 1 | |
[no-absolute-url][] | 1 | |
[no-get-location-abs-url][] | 1 | |
[no-expect-in-po][] | 1 | | requires plugin "settings"
[no-promise-in-if][] | 1 | |
[no-execute-script][] | 1 | | requires plugin "settings"
Expand Down Expand Up @@ -185,6 +187,7 @@ See [configuring rules][] for more information.
[valid-by-id]: docs/rules/valid-by-id.md
[valid-by-tagname]: docs/rules/valid-by-tagname.md
[no-get-raw-id]: docs/rules/no-get-raw-id.md
[no-get-location-abs-url]: docs/rules/no-get-location-abs-url.md
[configuring rules]: http://eslint.org/docs/user-guide/configuring#configuring-rules
## Recommended configuration
Expand Down
3 changes: 3 additions & 0 deletions docs/rules/no-get-location-abs-url.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Warn about using deprecated `getLocationAbsUrl()` method

`browser.getLocationAbsUrl()` was [deprecated in Protractor 5.1.0](https://github.com/angular/protractor/commit/8d2fc07ed28a1b19c03a9869442f76f2963e40a1) in favor of `browser.getCurrentUrl()`.
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ var noBrowserDriver = require('./lib/rules/no-browser-driver')
var validById = require('./lib/rules/valid-by-id')
var validByTagName = require('./lib/rules/valid-by-tagname')
var noGetRawId = require('./lib/rules/no-get-raw-id')
var noGetLocationAbsUrl = require('./lib/rules/no-get-location-abs-url')

module.exports = {
rules: {
Expand Down Expand Up @@ -70,7 +71,8 @@ module.exports = {
'no-browser-driver': noBrowserDriver,
'valid-by-id': validById,
'valid-by-tagname': validByTagName,
'no-get-raw-id': noGetRawId
'no-get-raw-id': noGetRawId,
'no-get-location-abs-url': noGetLocationAbsUrl
},
configs: {
recommended: {
Expand Down Expand Up @@ -106,6 +108,7 @@ module.exports = {
'protractor/use-count-method': 1,
'protractor/valid-by-id': 1,
'protractor/valid-by-tagname': 1,
'protractor/no-get-location-abs-url': 1,
'protractor/use-promise-all': 0,
'protractor/by-css-shortcut': 0,
'protractor/no-browser-driver': 0
Expand Down
28 changes: 28 additions & 0 deletions lib/rules/no-get-location-abs-url.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict'

/**
* @fileoverview Warn about deprecated browser.getLocationAbsUrl() method
* @author Alexander Afanasyev
*/

module.exports = {
meta: {
schema: []
},

create: function (context) {
return {
'CallExpression': function (node) {
var object = node.callee.object
var property = node.callee.property

if (object && property && object.name === 'browser' && property.name === 'getLocationAbsUrl') {
context.report({
node: node,
message: 'Unexpected browser.getLocationAbsUrl()'
})
}
}
}
}
}
32 changes: 32 additions & 0 deletions test/rules/no-get-location-abs-url.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use strict'

var rule = require('../../lib/rules/no-get-location-abs-url')
var RuleTester = require('eslint').RuleTester

var eslintTester = new RuleTester()

eslintTester.run('no-get-location-abs-url', rule, {
valid: [
'SomeObject.getLocationAbsUrl();',
'browser.wait(EC.visibilityOf(elm), 5000, "Message");'
],

invalid: [
{
code: 'browser.getLocationAbsUrl();',
errors: [
{
message: 'Unexpected browser.getLocationAbsUrl()'
}
]
},
{
code: 'browser.getLocationAbsUrl().then(function (url) { console.log(url) });',
errors: [
{
message: 'Unexpected browser.getLocationAbsUrl()'
}
]
}
]
})

0 comments on commit d33f8c8

Please sign in to comment.