Skip to content

Latest commit

 

History

History
70 lines (48 loc) · 2.87 KB

place-fields.md

File metadata and controls

70 lines (48 loc) · 2.87 KB

place-fields

Use the fields option to limit the fields returned by the API and costs. Requests to the Places API are billed by the fields that are returned. See Places Data SKUs for more details.

More information about fields for specific API calls can be found at the following links:

Note: This rule is not exhaustive. For example, it ignores Autocomplete.setFields().

📋 This rule is enabled in plugin:googlemaps/recommended.

🔧 The --fix option on the command line can automatically fix some of the problems reported by this rule.

Rule details

❌ Examples of incorrect code:

const service = new google.maps.places.PlacesService();
service.getDetails({place_id: 'foo'})

const service = new google.maps.places.PlacesService();
const request = {place_id: 'foo'};
service.getDetails(request)

const service = new google.maps.places.PlacesService();
service.getDetails({...{place_id: 'foo'}})

const service = new google.maps.places.Autocomplete(null, {});
const service = new google.maps.places.Autocomplete(null);

✔️ Examples of correct code:

const service = new google.maps.places.PlacesService();
const request = {place_id: 'foo', fields: ['place_id']};
service.getDetails(request)

const service = new google.maps.places.PlacesService();
service.getDetails({place_id: 'foo', fields: ['place_id']})

const service = new google.maps.places.PlacesService();
service.getDetails({...{place_id: 'foo', fields: ['place_id']}})

const service = new google.maps.places.PlacesService();
service.getDetails({...{place_id: 'foo', 'fields': ['place_id']}})

const service = new google.maps.places.PlacesService();
const buildRequest = () => {};
service.getDetails(buildRequest())

const service = new google.maps.places.Autocomplete(null, {fields: ['place_id']});

🔧 Examples of code fixed by this rule:

const service = new google.maps.places.PlacesService(); /* → */ const service = new google.maps.places.PlacesService();
service.getDetails({place_id: 'foo'})                   /* → */ service.getDetails({fields: /** TODO: Add necessary fields to the request */ [], place_id: 'foo'})

const service = new google.maps.places.PlacesService(); /* → */ const service = new google.maps.places.PlacesService();
service.getDetails({...{place_id: 'foo'}})              /* → */ service.getDetails({fields: /** TODO: Add necessary fields to the request */ [], ...{place_id: 'foo'}})

Resources